| |
Website :
http://www.youtube.com/watch?v=k1hz7oIoG4I
Credits :
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 |
| Navigate | |
|
| Detailed Info | |
|
| Fun Stuff | |
· Goofs · Hidden Parts · Trivia
|
|
| Forum | |
|
| Info on other sites | |
|
| Support CSDb | |
|
| |
|