;life...theslowversion:)#chip mega328p,16#option explicit#include<glcd.h>;#define GLCD_TYPE GLCD_TYPE_ILI9341'PinmappingsforSPI-thisGLCDdriversupportsHardwareSPIandSoftwareSPI#define GLCD_DC portb.2 ; DIGITAL_10 'HW Data command line DC#define GLCD_CS portd.7 ; DIGITAL_7 ' Chip select line CS#define GLCD_RESET portd.4 ; DIGITAL_4 ' Reset line Tie high..not needed#define GLCD_DO portb.3 ; DIGITAL 11 'HW Data out | MOSI SDI#define GLCD_SCK portb.5 ; DIGITAL_13 'HW Clock Line SCK#define ILI9341_HardwareSPI ' remove/comment out if you want to use software SPI.still slow'GLCDselectedextensionfontset.ASCIIcharacters31-254,theextendedfontuses1358bytesofprogrammemory#define GLCD_EXTENDEDFONTSET1GLCDfntDefaultsize=2GLCDRotate(landscape);dimii,tmp,pointer,cycleasworddimd1,rnd,readchar,printlineasbytecycle=0DIMw1(300)asbyte;15*20DIMn1(300)asbytedimp1(8)asbytefortmp=1to300;fillarrayswithspacesw1(tmp)=asc(" ")n1(tmp)=asc(" ")nexttmp;fortmp=1to50;50randomcellstostartrnd=random:rnd+=30;in300cellsw1(rnd)=asc("O")nexttmp;glcdclsILI9341_BLUEGLCDPrint(232,0,"CYCLE",ILI9341_SILVER)doFORii=22TO(300-22)d1=0;get8surroundingcellsintop1stringp1(1)=w1(ii-1);1stcellp1(2)=w1(ii+1)p1(3)=w1(ii-21)p1(4)=w1(ii-20)p1(5)=w1(ii-19)p1(6)=w1(ii+19)p1(7)=w1(ii+20)p1(8)=w1(ii+21);p1filledwithsurroundingcellvaluesn1(ii)=w1(ii)FORtmp=1TO8;p1istestoccupiedspacearoundcellIFp1(tmp)=asc("O")THENd1++endifNEXTtmp;testcellstateIF(w1(ii)=32)AND(d1=3)THENn1(ii)=asc("O"):GOTOdoneendifIF(w1(ii)=asc("O"))AND(d1<2)THENn1(ii)=32:GOTOdoneendifIF(w1(ii)=asc("O"))AND(d1>3)THENn1(ii)=32endifdone:NEXTii;testsdone;;printnewgenerationpointer=1fortmp=0to223step16;print15lines0to223yposdownscreen:chars16pixelshighforrnd=1to189step10;print20w1(x)charsacrossscreenGLCDPrint(rnd,tmp,chr(w1(pointer)),ILI9341_YELLOW)pointer++;nextcharinw1(pointer)nextrndnexttmp;GLCDPrint(232,16,str(cycle),ILI9341_WHITE)cycle++;fortmp=1to300;refreshw1()w1(tmp)=n1(tmp)nexttmploop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Note. The code in the posting may required a version of Great Cow BASIC greater than v.0.97.01. The array handler may need adapation in earlier versions of Great Cow BASIC, and early version of Great Cow BASIC did not support large arrays.
Recommend v0.98.00 or greater.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It is a straight conversion of a ZX Spectrum program https://rosettacode.org/wiki/Conway%27s_Game_of_Life Unclear Basic is "unique". You can say Dim w$(300):Dim n$(300):w$=n$. It was easier to convert to GCB than say bbc basic.
I've changed it so it wraps around one end of the array to the other ie top and bottom of screen wrap around.
I'll try to speed the display up. Life ran at a few fps full screen on a zx81 in machine code.
Compiler Version: 0.97.<<>> 2017-04-09 Program Memory: 8016 bytes RAM: 805/2048 bytes (39.31%) Chip: MEGA328P
Last edit: stan cartwright 2017-06-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium, "Create a buffer array as a buffer and only print changes in the output buffer."
Good idea. So I tried
; print new generation
pointer=1
for tmp = 0 to 223 step 16 ;print 111 lines 0 to 223 ypos down screen :chars 16 pixels high
for rnd = 1 to 189 step 10 ;print 20 w1(x) chars across screen
if w1(pointer) <> n1(pointer) then
GLCDDrawChar (rnd,tmp,w1(pointer),ILI9341_YELLOW)
end if
pointer ++ ;next char in w1(pointer)
next rnd
next tmp
but it didn't work, paper and pen says it should..only print cell in w1(xx) , old generation , if it's different to corresponding cell in n1(xx) , the new generation. The screen fills with "o"s after a while.
There's a 1024 dim array in include ssd1306 glcd so large arrays must be ok in this .97 version.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It's life Jim but not as we know it. ( ran faster on a zx81 :) )
https://youtu.be/geaXNmXHyd4
Note. The code in the posting may required a version of Great Cow BASIC greater than v.0.97.01. The array handler may need adapation in earlier versions of Great Cow BASIC, and early version of Great Cow BASIC did not support large arrays.
Recommend v0.98.00 or greater.
Consider these changes.
:-)
It is a straight conversion of a ZX Spectrum program https://rosettacode.org/wiki/Conway%27s_Game_of_Life Unclear Basic is "unique". You can say Dim w$(300):Dim n$(300):w$=n$. It was easier to convert to GCB than say bbc basic.
I've changed it so it wraps around one end of the array to the other ie top and bottom of screen wrap around.
I'll try to speed the display up. Life ran at a few fps full screen on a zx81 in machine code.
Compiler Version: 0.97.<<>> 2017-04-09 Program Memory: 8016 bytes RAM: 805/2048 bytes (39.31%) Chip: MEGA328P
Last edit: stan cartwright 2017-06-30
Anobium, "Create a buffer array as a buffer and only print changes in the output buffer."
Good idea. So I tried
but it didn't work, paper and pen says it should..only print cell in w1(xx) , old generation , if it's different to corresponding cell in n1(xx) , the new generation. The screen fills with "o"s after a while.
There's a 1024 dim array in include ssd1306 glcd so large arrays must be ok in this .97 version.