Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
  You are not logged in - nap
C64 Game of life   [2012]

C64 Game of life Released by :
Ruk

Release Date :
15 January 2012

Type :
C64 256b Intro

Website :
http://www.youtube.com/watch?v=k1hz7oIoG4I

User rating:awaiting 8 votes (1 left)   See votestatistics

Credits :
Code .... Ruk

Download :

Look for downloads on external sites:
 Pokefinder.org


Production Info
Submitted by ruk on 20 August 2013
Here's the main algorithm.

The rules for Conway's Game of Life are:

Any live cell with fewer than two live neighbours dies, as if caused by under-population.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overcrowding.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

As you can see, regardless if the cell is live or not, if the neighbour count is 3, the cell's new state is live.
Only other way a cell's new state can be live is if it's already live and the neighbour count is 2.

So what I did was to sum up all the neighbours, giving a value of 0 to 8.
Then, the acc is set to $0c if the current cell is active, or $08 if not. ( 00001100 or 00001000 )
By shifting this value right (LSR) as many times that there are live neighbours + 1, the new state of the cell is stored in the carry flag.

And in code:

screen:
        ldy #0
row:                                    //        MAX    MIN
        lda ($f8),y                     // Xoo    $21    $20
        adc ($fa),y                     // Xoo    $42    $40
        adc ($fc),y                     // Xoo    $63    $60
        iny
        iny
        adc ($f8),y                     // ooX    $84    $80
        adc ($fa),y                     // ooX    $a5    $a0
        adc ($fc),y                     // ooX    $c6    $c0
        dey
        adc ($f8),y                     // oXo    $e7    $e0
                                        // ooo                 actual cell (middle row) not considered yet
        adc ($fc),y                     // oXo    $08    $00   
        tax                             // store in x, value is in the range 0..8 (i.e. number of active neighbours)
        lda ($fa),y                     // The cell we're updating! $20 or $21 
        lsr                             // a = $10, carry set if cell was active
        bcs livecell                    
deadcell:
        lsr                             // a = $08 = 00001000 <- neighbour 'table' if cell was dead.           
        .byte $21                       // bit $0ca9 //skip the lda #$0c
livecell:
        lda #$0c                        // a = $0c = 00001100  <- neighbour 'table' if cell was active 
!:      lsr                             // shift neighbour table. An optional BEQ after this op could speed things up a bit.
        dex                             // 3 live neighbours -> 4 LSRs, if cell was dead -> C=1 otherwise C=0 
        bpl !-                          // 2-3 live neighbours -> 3-4 LSRs, if cell was live -> C=1 otherwise C=0
        lda #$10                        
        rol                             //ROL in active or dead cell from carry
        sta ($fe),y                     //Store $20 or $21 in buffer

        //loop until done and swap ptrs

Search CSDb
Advanced
Navigate
Prev - Random - Next
Detailed Info
· Summaries (1)
· User Comments (10)
· Production Notes (1)
Fun Stuff
· Goofs
· Hidden Parts
· Trivia
Forum
· Discuss this release
Info on other sites
· Pouët
Support CSDb
Help keep CSDb running:



Funding status:




About this site:
CSDb (Commodore 64 Scene Database) is a website which goal is to gather as much information and material about the scene around the commodore 64 computer - the worlds most popular home computer throughout time. Here you can find almost anything which was ever made for the commodore 64, and more is being added every day. As this website is scene related, you can mostly find demos, music and graphics made by the people who made the scene (the sceners), but you can also find a lot of the old classic games here. Try out the search box in the top right corner, or check out the CSDb main page for the latest additions.
Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.084 sec.