Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:33 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : [PicoMiteVGA] - Game of Life

Author Message
PEnthymeme

Regular Member

Joined: 27/12/2023
Location: United Kingdom
Posts: 42
Posted: 07:34pm 09 Jan 2024
Copy link to clipboard 
Print this post

Long time lurker as they say.

First up - thank you for a great community and re-igniting my latent passion.  Potted history - grew up on ZX81/Spectrum, moving to "PCs".  Industrial computing background (first paid program was a simulation of engine mounts in GW-BASIC), moved on as we do.

Found the "'Shed" during lockdown and went "PicoMite".

PicoMiteVGA is just about the "perfect" tinkering tool - powerful yet "BASIC" ;-)

Recently been tinkering with getting an "art" project up and running, based on Conway's Life.

PicoMiteVGA to RCA adapter (Amazon) and one of those reversing screen sold for cars (eBay).

Here seen running... (don't judge the set up)




The code... using sprites to save using arrays for the current and next generation. Added some "mutations" to keep things alive - resets after 100 generations...



'Based on Conway's Game of Life - PicoMiteVGA

'Grid Size
MODE 1
Const WIDTH = 340
Const HEIGHT =200
Const CELL = 10
Gens = 0
CLS

FRAMEBUFFER CREATE


createSprites()
'Create some sprites to copy for the cells


'set up inital screen
FRAMEBUFFER WRITE F

For x = 10 To WIDTH Step CELL
 For y = 10 To HEIGHT Step CELL
   alive = Int(Rnd*2)
   If alive = 1 Then
     Sprite WRITE 1,x, y
   EndIf
 Next
Next

FRAMEBUFFER COPY f,n

'main loop
Do
gens = gens + 1
If gens = 101 Then Run
'clear out the next screen
FRAMEBUFFER write f
CLS

Colour RGB(white)
Text 0,260, "Generation " +Str$(gens)
Colour RGB(black)

For x = 10 To WIDTH Step CELL
 For y = 10 To HEIGHT Step CELL
   FRAMEBUFFER write n  'count neighbours on current
   aliveNeighbours = countNeighbours(x,y)
   pixCol = Pixel(x+5,y+5) 'move to cell centre

   FRAMEBUFFER write f  'move back to new screen for all updates
   If pixCol = 16777215 Then

     If aliveNeighbours <2 Or aliveNeighbours > 3 Then
       Sprite write 2,x,y
     Else

       Sprite write 1,x,y
     EndIf
   Else
     If aliveNeighbours = 3 Then

       Sprite write 1,x,y
     EndIf
   EndIf
   'spontaneous creation and dying - added to allow sim to run longer

   mutate =Rnd()
   If mutate < 0.01 Then
     Sprite write 2,x,y  'spontaneous death
   ElseIf mutate > 0.999 Then
     Sprite write 1,x,y  'spontaneous life
   EndIf

 Next y
Next x


FRAMEBUFFER copy f,n

Loop



Function countNeighbours(x,y)
 count = 0
 For dx = -10 To 10 Step CELL
   For dy = -10 To 10 Step CELL
     If (dx= 0 And dy=0) Then
     ' dont count yourself
     Else
         nx = (x+dx+WIDTH) Mod WIDTH
         ny = (y+dy+HEIGHT) Mod HEIGHT
         pixCol = Pixel(nx+5,ny+5)
         If pixCol = 16777215 Then
           count = count + 1
         EndIf
     EndIf
   Next dy
 Next dx
 countNeighbours = count
End Function



Sub createSprites()
 Colour RGB(black)
 Circle 10,10,5,,,,RGB(white)
 Sprite read 1, 5,5,15,15

 Colour RGB(black)
 Circle 10,10,5,,,,RGB(black)
 Sprite read 2, 5,5,15,15
End Sub




I know "life" is computationally intensive with the looping over all the "cells" and their neighbors -- but open to suggestions how to make things faster as at this resolution to update is acceptable for an art project, but generally "slow" compared to the games I see here.

The next step will be to change the mutations to either read and LDR or temperature and mutate based on environmental conditions.

Anyways - that's me - finally dipped my head above the parapet.

Px
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4234
Posted: 08:15pm 09 Jan 2024
Copy link to clipboard 
Print this post

Thank you for your first contribution.
The code is very clear and well written.

About speed
The sub that counts neighbors is eating 90% of the cpu cycles.
Any tuning should be in that sub for best performance.

One thing could be to avoid calculations for every cell counted.
There are 8, and they are at fixed relative positions from x,y.
X-5,y-5
X+15,y-5
Etc…

Nice VGA to CVBS converter. Some people on this forum are looking for such converter.
What is the type?

Volhout
PicomiteVGA PETSCII ROBOTS
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 08:39pm 09 Jan 2024
Copy link to clipboard 
Print this post

Mini VGA to BNC

Nice work--thanks for posting. And welcome to the interactive part of the forum.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
PEnthymeme

Regular Member

Joined: 27/12/2023
Location: United Kingdom
Posts: 42
Posted: 09:36pm 09 Jan 2024
Copy link to clipboard 
Print this post

  Volhout said  

One thing could be to avoid calculations for every cell counted.
There are 8, and they are at fixed relative positions from x,y.
X-5,y-5
X+15,y-5
Etc…

Nice VGA to CVBS converter. Some people on this forum are looking for such converter.
What is the type?

Volhout


Nice - will see what I can do there - one for tomorrow.

The CVBS is as @lizby posted - had it for a while via slow boat from who knows where - another lockdown "treat".

Long term, i'll make up a PicoMite VGA on protoboard for this as I wont then need the SD card / Keyboard and it'll be quite compact then - ideally fit directly behind the monitor itself - the plan will then be to mount it on a self as "art"  -- Or so I keep telling my other half as I try to convince her I'm not a hoarder.

Thanks
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4234
Posted: 09:45pm 09 Jan 2024
Copy link to clipboard 
Print this post

The sd card may be essential. There are cheap, breadboard friendly modules.

Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4234
Posted: 09:45pm 09 Jan 2024
Copy link to clipboard 
Print this post

The sd card may be essential. There are cheap, breadboard friendly modules.

Volhout
PicomiteVGA PETSCII ROBOTS
 
PEnthymeme

Regular Member

Joined: 27/12/2023
Location: United Kingdom
Posts: 42
Posted: 11:04pm 09 Jan 2024
Copy link to clipboard 
Print this post

  Volhout said  The sd card may be essential. There are cheap, breadboard friendly modules.

Volhout


Are the micro SD card modules functionally the same or do I need a full sized SD Card?

P
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 11:13pm 09 Jan 2024
Copy link to clipboard 
Print this post

They are the same. If you have a spare micro/standard SD adapter here is an option.




SD Card pins (bottom view)
nc CS MOSI ⏚  3V3 SCK  ⏚ MISO nc
  _______________________________
 / 1   2   3   4   5   6   7   8 |
/9 CS MOSI ⏚  3V3 SCK  ⏚ MISO nc|
|nc                              |
|                                |

Edited 2024-01-10 09:17 by phil99
 
PEnthymeme

Regular Member

Joined: 27/12/2023
Location: United Kingdom
Posts: 42
Posted: 11:24pm 09 Jan 2024
Copy link to clipboard 
Print this post

  phil99 said  
SD Card pins (bottom view)
nc CS MOSI ⏚  3V3 SCK  ⏚ MISO nc
  _______________________________
 / 1   2   3   4   5   6   7   8 |
/9 CS MOSI ⏚  3V3 SCK  ⏚ MISO nc|
|nc                              |
|                                |


Reminds me of PS3 modchipping (so I am told)

What's the cap F - 0.1uF?

P
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 11:41pm 09 Jan 2024
Copy link to clipboard 
Print this post

The cap filters the 3V3 supply and is optional, most µSD cards don't need it.
If the card doesn't always respond add 10µF, a 100µF was in front of me so I put it on, though not needed for that card.
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 12:33am 10 Jan 2024
Copy link to clipboard 
Print this post

  PEnthymeme said  Are the micro SD card modules functionally the same or do I need a full sized SD Card?


This micro SD module works well for me, with maybe a half-dozen hooked up to picomites.

Some have said that the inline resistors on that module might cause problems, but I haven't seen any. Wired one with flying leads a few days ago to the bottom row of pins on one of these:

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 12:34am 10 Jan 2024
Copy link to clipboard 
Print this post

works but small display (on small vga) and slow refresh sorry. zx spectrum was fast.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4234
Posted: 07:18am 10 Jan 2024
Copy link to clipboard 
Print this post

Maybe this could help improve

See chapter 17

Graphics Programming

Volhout
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6792
Posted: 08:22am 10 Jan 2024
Copy link to clipboard 
Print this post

@lizby

I traced the circuit of one of those uSD card modules. There are two supply decoupling capacitors and pullup (not inline) resistors on the signal pins. As the resistors are pretty high in value (10K) they don't seem to have any effect. I've used these a few times now with no additional decoupling and they've always worked well for me. Note, they are a true 3V3 module. There is no level shifting so they are ideal for a Pico.

Another fan of the RP2040-Zero. :)

.
Edited 2024-01-10 18:25 by Mixtel90
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 200
Posted: 04:00pm 10 Jan 2024
Copy link to clipboard 
Print this post

PENthymeme - welcome!

VegiPete provided an excellent set of routines for neighbor detection and generation, uh, generation :-) I adapted those routines for a version of LIFE described in this posting.

My setup is mainly based around the WaveShare boards, many of which have integral SD card receptacles. I have yet to try the PicoVGA, which (from what I hear) works much faster on screen updates than LCDs. Curious to see what kinds of speeds you see.
Live in the Future. It's Just Starting Now!
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1241
Posted: 04:44pm 10 Jan 2024
Copy link to clipboard 
Print this post

@PEnthymeme: Welcome!

  PEnthymeme said  ... but open to suggestions how to make things faster as at this resolution to update is acceptable for an art project, but generally "slow" compared to the games I see here.


How about using CSubs to count neighbors?  
My version  took ~6ms/gen for a 64x64 field on a CMM2.

  PEnthymeme said  The next step will be to change the mutations to either read and LDR or temperature and mutate based on environmental conditions.


Interesting idea!  

Regards Michael
Edited 2024-01-11 02:51 by twofingers
causality ≠ correlation ≠ coincidence
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024