Show Posts
Pages: 1 [2] 3 4 ... 27
16  Community / Exhibition / Gallery / Re: Conway's Game Of Life with TVout 128 x 96 pixels on: May 13, 2014, 06:06:58 pm
"becomes stable after 1800 generations without wrap around" I should have said!
On the Arduino R-pentomino takes around 3-4 minutes to become stable.

My Apple II code started out in Applesoft floating basic, going to integer Apple Basic sped things up, but took too long, so I wrote a hand assembled machine code version that ran pretty damn fast
17  Community / Exhibition / Gallery / Re: Conway's Game Of Life with TVout 128 x 96 pixels on: May 01, 2014, 05:07:00 am
I made a small change, starts off with R Pentomino rather than a random pond.
R Pentomino spawns 5 gliders in the first 30 odd generations, becomes "stable" after 1800 generations.

My first Apple II Life program took nearly a day to do 1800 generations!

Code:
// Conway's Game Of Life 128x96 using TVout
// P.Beard
// March 2013

#include <TVout.h>

#define matWidth 4
#define matHeight 96

TVout TV;
unsigned long * myScreen;

void setup() {
  TV.begin(PAL, matWidth * 32, matHeight);
  myScreen = (unsigned long *) TV.screen;
  randomSeed(analogRead(0));
  randomiseMatrix();
}

void loop() {
  generateMatrix();
  digitalWrite(13, !digitalRead(13));
}

unsigned long swapBytes(unsigned long x) {
  return ((x & 0x000000ffUL) << 24) | ((x & 0x0000ff00UL) << 8) | ((x & 0x00ff0000UL) >> 8) | ((x & 0xff000000UL) >> 24);
}

void randomiseMatrix() {
//start with R pentomino
  byte col = random(matWidth);
  byte row = random(matHeight);
  myScreen[(row+0) * matWidth + col] |= B0000011;
  myScreen[(row+1) * matWidth + col] |= B0000110;
  myScreen[(row+2) * matWidth + col] |= B0000010;
 
//  //Set up initial cells in matrix
//  for (int r = 0; r < matHeight; r++) {
//    for (int c = 0; c < matWidth; c++) {
//      myScreen[r * matWidth + c] = random(0xffff) << 16 | random(0xffff);
//    }
//  }
}

void injectGlider() {

  byte col = random(matWidth);
  byte row = random(matHeight);
  myScreen[(row+0) * matWidth + col] |= B0000111;
  myScreen[(row+1) * matWidth + col] |= B0000001;
  myScreen[(row+2) * matWidth + col] |= B0000010;
}


void generateMatrix() {
 
  //Variables holding data on neighbouring cells
  unsigned long NeighbourN[matWidth], NeighbourNW[matWidth], NeighbourNE[matWidth], CurrCells[matWidth], NeighbourW[matWidth];
  unsigned long NeighbourE[matWidth], NeighbourS[matWidth], NeighbourSW[matWidth], NeighbourSE[matWidth], firstRow[matWidth];

  unsigned long tot1, tot2, tot4, carry, NewCells;

  int changes = 0; // counts the changes in the matrix
  static int prevChanges = 256; // counts the changes in the matrix on prev generation
  static int staleCount = 0; // counts the consecutive occurrances of the same number of changes in the matrix

  //set up N, NW, NE, W & E neighbour data
  //also take a copy of the first row data for use later when calculating last row
  for (byte b = 0; b < matWidth; b++) {
    NeighbourN[b] = swapBytes(myScreen[(matHeight-1) * matWidth + b]);
    firstRow[b] = CurrCells[b] = swapBytes(myScreen[b]);
  }

  carry = NeighbourN[matWidth-1];
  for (char b = 0; b < matWidth; b++) {
    NewCells = NeighbourN[b];
    NeighbourNW[b] = NewCells >> 1 | carry << 31;
    carry = NewCells;
  }
 
  carry = NeighbourN[0];   
  for (char b = matWidth-1; b >= 0; b--) {
    NewCells = NeighbourN[b];
    NeighbourNE[b] = NewCells << 1 | carry >> 31;
    carry = NewCells;
  }

  carry = CurrCells[matWidth-1];
  for (char b = 0; b < matWidth; b++) {
    NewCells = CurrCells[b];
    NeighbourW[b] = NewCells >> 1 | carry << 31;
    carry = NewCells;
  }
 
  carry = CurrCells[0];   
  for (char b = matWidth-1; b >= 0; b--) {
    NewCells = CurrCells[b];
    NeighbourE[b] = NewCells << 1 | carry >> 31;
    carry = NewCells;
  }
 
  //Process each row of the matrix
  for (byte row = 0; row < matHeight; row++) {

    //Pick up new S, SW & SE neighbours
    if (row < matHeight - 1) {
      for (byte b = 0; b < matWidth; b++) {
        NeighbourS[b] = swapBytes(myScreen[(row+1) * matWidth + b]);
      }
    }
    else {
      for (byte b = 0; b < matWidth; b++) {
        NeighbourS[b] = firstRow[b];
      }
    }
 
    carry = NeighbourS[matWidth-1];
    for (char b = 0; b < matWidth; b++) {
      NewCells = NeighbourS[b];
      NeighbourSW[b] = NewCells >> 1 | carry << 31;
      carry = NewCells;
    }
     
    carry = NeighbourS[0];   
    for (char b = matWidth-1; b >= 0; b--) {
      NewCells = NeighbourS[b];
      NeighbourSE[b] = NewCells << 1 | carry >> 31;
      carry = NewCells;
    }
 
    for (char b = 0; b < matWidth; b++) {
     
       //Count the live neighbours (in parallel) for the current row of cells
      //However, if total goes over 3, we don't care (see below), so counting stops at 4
      tot1 = NeighbourN[b];
      tot2 = tot1 & NeighbourNW[b]; tot1 = tot1 ^ NeighbourNW[b];
      carry = tot1 & NeighbourNE[b]; tot1 = tot1 ^ NeighbourNE[b]; tot4 = tot2 & carry; tot2 = tot2 ^ carry;
      carry = tot1 & NeighbourW[b]; tot1 = tot1 ^ NeighbourW[b]; tot4 = tot2 & carry | tot4; tot2 = tot2 ^ carry;
      carry = tot1 & NeighbourE[b]; tot1 = tot1 ^ NeighbourE[b]; tot4 = tot2 & carry | tot4; tot2 = tot2 ^ carry;
      carry = tot1 & NeighbourS[b]; tot1 = tot1 ^ NeighbourS[b]; tot4 = tot2 & carry | tot4; tot2 = tot2 ^ carry;
      carry = tot1 & NeighbourSW[b]; tot1 = tot1 ^ NeighbourSW[b]; tot4 = tot2 & carry | tot4; tot2 = tot2 ^ carry;
      carry = tot1 & NeighbourSE[b]; tot1 = tot1 ^ NeighbourSE[b]; tot4 = tot2 & carry | tot4; tot2 = tot2 ^ carry;

      //Calculate the updated cells:
      // <2 or >3 neighbours, cell dies
      // =2 neighbours, cell continues to live
      // =3 neighbours, new cell born
      NewCells = (CurrCells[b] | tot1) & tot2 & ~ tot4;
     
      //Have any cells changed?
      if (NewCells != CurrCells[b]) {
        myScreen[row * matWidth + b] = swapBytes(NewCells);
        //Count the change for "stale" test
        changes++;
      }
     
      //Current cells (before update), E , W, SE, SW and S neighbours become
      //new N, NW, NE, E, W neighbours and current cells for next loop
      NeighbourN[b] = CurrCells[b];
      NeighbourNW[b] = NeighbourW[b];
      NeighbourNE[b] = NeighbourE[b];
      NeighbourE[b] = NeighbourSE[b];
      NeighbourW[b] = NeighbourSW[b];
      CurrCells[b] = NeighbourS[b];
    } //next col
  } //next row
   
  if (changes != prevChanges) staleCount = 0; else staleCount++; //Detect "stale" matrix
  if (staleCount > 32) injectGlider(); //Inject a glider

  prevChanges = changes;
}
18  Community / Bar Sport / Re: Are microcontrollers considered to be kiddies toys in real world? on: April 30, 2014, 01:06:59 am
My DX4-100 is/was the "ducks guts"!

It has the VLB MF card from hell, SCSI, 2x serial, 2x parallel, 2x joystick, IDE, floppy.

Just to be totally elitist, it's a pure SCSI system, dual boot DR-DOS and Debian!
19  Community / Exhibition / Gallery / Re: Conway's Game Of Life with TVout 128 x 96 pixels on: April 24, 2014, 06:16:48 am
This works REALLY well!

Looks great on my 37" Sony BRAVIA!!!
20  Community / Bar Sport / Re: Are microcontrollers considered to be kiddies toys in real world? on: April 24, 2014, 12:56:51 am
Apple did a deal with all the schools in South Australia that had Apple II euro plus machines, the ones that were all TTL, they replaced them with the newer version that had 128k and a board that only had a few 40 pin DIPS.
I took home about 40 complete Apple II's.
They all boot fine, finding 5-1/4" floppies these days is a bit hard, my main worry is drives, in particular the head amp chip.

TTL, 7400 series and VLSI chips seem to last forever, my Synertek SYM-1 is still going strong after 35 years!
21  Community / Bar Sport / Re: Are microcontrollers considered to be kiddies toys in real world? on: April 24, 2014, 12:27:08 am
I would rather nail my penis to a burning building or be seen driving a ford than run windoze 8!

no fear on the dead Apple, I have enough bits to keep a few dozen running for years to come!
22  Community / Bar Sport / Re: Are microcontrollers considered to be kiddies toys in real world? on: April 23, 2014, 09:41:17 pm
Remember most folks computing power is inversely proportional to their skills

Which is why I get little dweebs giving me grief about still having and using a DX4-100, Macintosh Plus and an Apple II
23  Community / Bar Sport / Re: Are microcontrollers considered to be kiddies toys in real world? on: April 20, 2014, 03:37:19 am
my first thought was, "How would I build a USB Mouse without a microcontroller"?

I've built UART's in 74x and 4000 series, but a more complex circuit is a nightmare!

This is coming from someone that REALLY likes building big, complex things out of 7400 chips!

When you consider that "Pong" was a single board, about 16"(?) square, PACKED with 7400 TTL, that drew around 5A!!
I can now haz "Pong" with a single 324, a couple of resistors, 2 pots and a speaker.

24  Community / Exhibition / Gallery / Re: Text Printer (stepper, servos, and a marker) on: March 08, 2014, 01:19:31 am
Very Cool!
Reminds me of a printer I have somewhere that uses tiny ball point pens
25  Community / Bar Sport / Re: Whiplash from a topic search ! on: February 26, 2014, 02:34:17 am
Grampa used to get asked to go all over the Mount Lofty Ranges.

He was always right on the money.

I was always sceptical, even after I dug a shallow well (3 metres) in a spot he had said was good.
26  Community / Bar Sport / Re: Whiplash from a topic search ! on: February 25, 2014, 10:58:34 pm
my great grand father used to "dowse" for water with a pendulum, he was scary accurate!

I saw him dowse with coat hangers as well.

Before you all cry "rubbish", the proof was in the well!
27  Community / Bar Sport / Re: For the seasoned contributors on: February 01, 2014, 09:02:40 pm
just to throw another spanner in the works...

isn't tab diet cola?

 ;-)
28  Community / Bar Sport / Re: For the seasoned contributors on: February 01, 2014, 11:47:03 am
every now and then I get strange looks when I say "Hit return"

"What's return?"

me, "You know, carriage return."

"Where's that on the keyboard?"

me, "FFS! It's the big key on the right, near the numeric keypad!!!"

"You mean enter"

29  Community / Bar Sport / Re: What do you call a citizen of the United Kingdom? on: January 03, 2014, 09:54:44 pm
Australians are inherintly racist to the English.

In the 12 years I've lived here (Australia) I've seen more casual rasists than anywhere else.... just from every day language which they think is fine...

Pom is racist, refering to color of skin .



Rubbish!
It's an affectionate term!

Besides they need a little "push", now that they can't bat, bowl or field!!

btw, I'm WAY paler than the average ten dollar pom!
30  Community / Exhibition / Gallery / Re: Heavily Modified Power Wheels on: January 03, 2014, 02:53:13 pm
That is so cool!

Parenting, you're doing it right!!
Pages: 1 [2] 3 4 ... 27