Conway's Game Of Life


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    From 3 to 15 frames per second in a couple of hours, I call that improvement.
    At one place (at least) you first do IF LED[Counter] = 0 and then a couple of lines further down you do IF LED[Counter] > 0 which seems a bit of a wate since you already know if it IS 0 and if it's not it's got to be > 0 (since it can't be negative in case you're not using LONGs). There's also Population = Population + 1 in 8 places, can you move that outside each of the IF/THEN statements and only have ONE of them? That likely won't increase performance but will save space (if that matter at all).

    We're probably talking microseconds here but since it all executes 1024 times per frame it does add up.

    Anyhow, nice job and keep those updates and videos coming!

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Quote Originally Posted by HenrikOlsson View Post
    From 3 to 15 frames per second in a couple of hours, I call that improvement!
    Thanks to all who have contributed so far.

    I will post the complete code and circuit schematic etc when I have it finished and we can't eek out any more speed.

    I tweaked if LED[Counter] = 0 and that gives another HZ I think.

    Code space is not an issue. RAM Might be later.
    Last edited by retepsnikrep; - 23rd May 2020 at 15:16.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,645


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    last time i played with "life" i never found a way to detect a stable repetitive cycling pattern.
    are you determining if boring stuck patterns ensue ?
    Warning I'm not a teacher

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Quote Originally Posted by richard View Post
    last time i played with "life" i never found a way to detect a stable repetitive cycling pattern.
    are you determining if boring stuck patterns ensue ?
    Currently i'm using three things.

    1) A simple maximum number of generations reset limit (500). That catches everything.

    2) A simple live cell counter. If it's zero then it resets.

    3) A pseudo checksum which seem to work quite well.

    A word variable to which the address of every populated cell is added, it may overflow many times, and after all 1024 cells have been generated/examined you end up with a number.
    It also calculates the checksum for the next generation and if it matches the previous generation then it probably means we have a stuck pattern and resets.

    I've been testing this for thousands of patterns and generations now and it works well.
    It only falls back on the hard generation limit with huge repeating patterns that cycle over several generations.
    It detects small oscillators and stuck patterns etc quite well.

    I appreciate it is possible for two patterns to have the same checksum but the odds must be very very small.

    Cross post with Richard LOL!! Basically what I'm doing but I'm not quite as clever as the 'Life' experts.
    Last edited by retepsnikrep; - 24th May 2020 at 11:24.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Thanks Henrick..

    If the array transform only takes call it ~5ms per generation then at 15hz it's using 75ms in a second.
    Roughly equivalent to one extra generation per second. Getting close to not much return for our efforts..

    Do we think we can directly evaluate the Neopixel array with it's weird layout.. ?

    I'm going to set my display up with some timing pins today and have a fiddle about.

    Thanks for all the interesting replies.

  6. #6
    Join Date
    Aug 2011
    Posts
    453


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    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.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    For the big evaluation routine we currently have this giving about 15hz

    Code:
    '----------------------- Also creating a newled data array to be displayed on next generation -------------
    
    FOR counter = 0 TO 1023
    
    	population = 0 :topedge	= 0 :botedge = 0 :lefedge = 0 :rigedge = 0
    
    'Grid Edge Detection
    	
    	IF counter < 32 THEN botedge = 1
    
    	IF counter > 991 THEN topedge = 1
    	
    '*******************************************************************************	  	
    	
        TempCount = Counter & 31
        If TempCount = 0 THEN
        lefedge = 1
        ENDIF
    
    
        IF TempCount = 31 THEN
        rigedge = 1
        ENDIF	
    	
    '*******************************************************************************		
    
    'Grid Evaluation	 
    
    
    CntPlus33 = Counter + 33
    CntPlus32 = Counter + 32
    CntPlus31 = Counter + 31
    CntPlus1 = Counter +1
    
    CntMinus33 = Counter - 33
    CntMinus32 = Counter - 32
    CntMinus31 = Counter - 31
    CntMinus1 = Counter - 1	        	
    	
    	IF led[CntMinus1] > 0 THEN
          IF counter > 0 THEN
    	    Colour[population] = led[CntMinus1]
    		population = population + 1
    	  ENDIF
    	ENDIF
    	
    	IF led[CntPlus1] > 0 THEN
          IF counter < 1023 THEN
    	    Colour[population] = led[CntPlus1]
    		population = population + 1  		
           ENDIF
        ENDIF
    	
    	IF botedge = 0 THEN
    		IF led [CntMinus31] > 0 THEN
    		    Colour[population] = led[CntMinus31]
    			population = population + 1			
    		ENDIF
    		IF led [CntMinus32] > 0 THEN
    		    Colour[population] = led[CntMinus32]  
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 then
                if led [CntMinus33] > 0 THEN
    		    Colour[population] = led[CntMinus33]
    			population = population + 1
    			endif
    		ENDIF
    	ENDIF
    	
    	IF topedge = 0 THEN
    		IF led [CntPlus31] > 0 THEN
    		    Colour[population] = led[CntPlus31]
    			population = population + 1
    		ENDIF
    		IF led [CntPlus32] > 0 THEN
    		    Colour[population] = led[CntPlus32]
    			population = population + 1
    		ENDIF
    		IF  rigedge = 0 then 
                if led [CntPlus33] > 0 THEN 
    		    Colour[population] = led[CntPlus33]
    			population = population + 1
    			endif
    		ENDIF
    	ENDIF       
    
        lednew[counter] = led[counter]
    	
    	IF led[counter] = 0 THEN
    		IF population = 3 THEN
    		
    		    if Colour[0] = Colour[1] then
    		    lednew[counter] = Colour[0]
    		    
    		    elseif Colour[0] = Colour[2] then
                lednew[counter] = Colour[0]
                
                elseif Colour[1] = Colour[2] then
                lednew[counter] = Colour[1]
                
        	    endif   	
    			
    		ENDIF
    	else   	
    		IF population > 3 OR population < 2 THEN
    			lednew[counter] = 0
    		ENDIF
    			
    	ENDIF
    
    NEXT counter
    Last edited by retepsnikrep; - 23rd May 2020 at 15:20.

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    This shaved another 4ms off here, instead of:
    Code:
    IF population > 3 OR population < 2 THEN
      lednew[counter] = 0
    ENDIF
    Do:
    Code:
    IF Population > 3 THEN LEDNew[Counter] = 0
    IF Population < 2 THEN LEDNew[Counter] = 0
    We're trading readabillity for performance here...

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Conway's Game Of Life

    Thanks. All good stuff. I think we are getting near the limit.

    The actual output to the WS2812B 1024 NeoPixel array is handled by the large mixed basic/assembler subroutine below.

    I made a couple of small mods so it could work with 1024 leds and one data array holding the LED colour info encoded in bits 5,6,7 and brightness from 0-31 in bits 0-4.
    I found brightness of 31 was really bright enough for daytime use and kept power supply requirements within reasonable wall wart limits.

    So once the NeoLed array is loaded with the data this routine is called and loops until all 1024 led data has been output.

    Code:
    NeoPixelASM64:'------------- subroutine call name ----------------
    	POINTER = NEO_NUM - 1	'THIS SCHEME USED TO ELIMINATE USING "< or >" COMPARE STATEMENTS
    	SCRATCH = NEO_NUM - 1	'THIS SCHEME USED TO ELIMINATE USING "< or >" COMPARE STATEMENTS	
    
    
    DOGREEN:
    	NeoPixel = SCRATCH - POINTER	'PUSH PIXELS FROM LOWEST to HIGHEST! DON'T ASK ME WHY?
    	
    	NeoPixValue = NeoLed(NeoPixel)	'First, the Green array
    	
    'Colours %000 10000   (Bits 0-4 Intensity 32 steps 0-31 Default 31)  Bits 5-6-7 (001 Red D32) (010 Green D64) (100 Blue D128)	
    
    	If NeoPixValue.6 = 1 then 
        NeoPixValue = NeopixValue & Brightness    'Clear Colour bits & set Green Intensity
        else 
        NeoPixValue = 0                           'Turn LED Off
        endif         
    	
    	NEOPIN = 1
    ASM
    		btfsc   _NeoPixValue, 007h
    	    Bra doneg70
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg71
    doneg70
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doneg71
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 006h
    	    Bra doneg60
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg61
    doneg60
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doneg61
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 005h
    	    Bra doneg50
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg51
    doneg50
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doneg51
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 004h
    	    Bra doneg40
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg41
    doneg40
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneg41
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 003h
    	    Bra doneg30
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg31
    doneg30
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doneg31
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 002h
    	    Bra doneg20
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg21
    doneg20
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneg21
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 001h
    	    Bra doneg10
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg11
    doneg10
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneg11
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 000h
    	    Bra doneg00
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneg01
    doneg00
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneg01
    endasm
    
    	NeoPixValue = NeoLed(NeoPixel)     'Second, the Red array
    	
    'Colours %000 10000   (Bits 0-4 Intensity 32 steps 0-31 Default 31)  Bits 5-6-7 (001 Red D32) (010 Green D64) (100 Blue D128)
    	
    	If NeoPixValue.5 = 1 then 
        NeoPixValue = NeoPixValue & Brightness        'Clear Colour bits & set Red Intensity
        else 
        NeoPixValue = 0                           'Turn LED Off
        endif  	
    	
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 007h
    	    Bra doneb70
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb71
    doneb70
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doneb71
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 006h
    	    Bra doneb60
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb61
    doneb60
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doneb61
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 005h
    	    Bra doneb50
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb51
    doneb50
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doneb51
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 004h
    	    Bra doneb40
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb41
    doneb40
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneb41
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 003h
    	    Bra doneb30
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb31
    doneb30
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doneb31
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 002h
    	    Bra doneb20
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb21
    doneb20
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneb21
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 001h
    	    Bra doneb10
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb11
    doneb10
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneb11
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 000h
    	    Bra doneb00
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doneb01
    doneb00
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doneb01
    endasm
    
    	NeoPixValue = NeoLed(NeoPixel)        'Lastly, the Blue array
    	
    'Colours %000 10000   (Bits 0-4 Intensity 32 steps 0-31 Default 31)  Bits 5-6-7 (001 Red D32) (010 Green D64) (100 Blue D128)
    	
    	If NeoPixValue.7 = 1 then 
        NeoPixValue = NeoPixValue & Brightness    'Clear Colour bits & set Blue Intensity
        else 
        NeoPixValue = 0                           'Turn LED Off
        endif  	 	
    	
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 007h
    	    Bra doner70
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner71
    doner70
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doner71
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 006h
    	    Bra doner60
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner61
    doner60
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doner61
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 005h
    	    Bra doner50
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner51
    doner50
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    doner51
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 004h
    	    Bra doner40
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner41
    doner40
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    ;		Bcf LATA,3
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doner41
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 003h
    	    Bra doner30
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner31
    doner30
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
     		NOP
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
    doner31
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 002h
    	    Bra doner20
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner21
    doner20
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doner21
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 001h
    	    Bra doner10
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner11
    doner10
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doner11
    ENDASM
    	NEOPIN = 1
    ASM	
    		btfsc   _NeoPixValue, 000h
    	    Bra doner00
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		bra doner01
    doner00
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    		NOP
    ENDASM
    	NEOPIN = 0
    ASM	
    		NOP
    		NOP
    		NOP
    		NOP
     		NOP
     		NOP
    doner01
    endasm
    	POINTER = POINTER - 1	'next pixel in the string
    	IF POINTER.15 = 0 THEN DOGREEN' < NEO_NUM THEN DOGREEN
    
    	return		'get back to main program.........

  10. #10


    Did you find this post helpful? Yes | No

    Default Evaluate the Neopixel array directly

    So a final effort to save 1024 bytes of RAM, one complete array, and perhaps give some increase in speed would be to be able to directly evaluate the odd neopixel array layout.

    As I mentioned the Neopixel array is a physical snakes and ladders arrangement of 1024 series connected leds, starting 0 bottom left and ending 1023 top left of the grid.

    The two life arrays are in the conventional x/y layout, starting 0 bottom left and finishing 1023 top right.


    Currently once the Life array evaluation is completed it then has to be parsed and converted to fit the neopixel LED array layout.

    If I could evaluate the Neopixel array directly we would save 1024 bytes and eliminate the parsing and conversion routine below, although I don't know how long that actually takes to execute.

    Of course the evaluation routine would become more complicated, so the trade off speed benefits may be minimal or non existent. However even if speed worked out the same it would save the 1024 bytes of ram.

    Code:
       	alive = 0	            'Clears alive accumulator
    	dead = 0                'Clears dead checksum accumulator
    
      FOR Row = 0 to 31			' Cycle thru 32 rows
         
         TempW = ROW * 32       ' Precalculate this instead of doing it every time thru the loop
         
         FOR Col = 0 to 31			' of 32 pixels each          
           InPtr = (TempW) + Col   '  
           led[InPtr] = lednew[InPtr]         
           IF Row.0 = 0 THEN	' If the row number is even   
             OutPtr =  InPtr        ' Output pixels in true order       
           ELSE
             OutPtr = (TempW) + (31-Col)   ' Output pixels in reversed order        
           ENDIF
           
           IF led[InPtr] > 0 THEN
           NeoLed(OutPtr) = Led[InPtr]	
           alive = alive + 1
           dead = dead + InPtr
    	   else 
           NeoLed(OutPtr) = 0	
    	   ENDIF
          
         NEXT
         NEXT

Similar Threads

  1. programming jumping game
    By bokken in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th February 2012, 06:40
  2. Simon Game
    By flotulopex in forum Code Examples
    Replies: 1
    Last Post: - 4th November 2010, 06:25
  3. EEPROM life expectancy?
    By muddy0409 in forum General
    Replies: 3
    Last Post: - 1st May 2007, 12:44
  4. home brew game console W interface
    By PICMAN in forum General
    Replies: 1
    Last Post: - 15th March 2005, 22:25
  5. Game port to USB adaptor
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th September 2004, 03:16

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts