1 ; Conway\'s Game of Life
2 ; http://rosettacode.org/wiki/Conway\'s_Game_of_Life
3 ; Submitted by Anonymous
5 randfill: stx $01 ;$200 for indirect
8 randloop: lda $fe ;generate random
9 and #$01 ;pixels on the
19 clearmem: lda #$df ;set $07df-$0a20
34 copyscreen: lda #$00 ;set up source
37 lda #$02 ;dest pointer
42 copybyte: lda ($01),Y ;copy pixel to
43 sta ($03),Y ;back buffer
44 jsr inc0103 ;increment pointers
45 cmp #$00 ;check to see
46 bne copybyte ;if we\'re at $600
47 lda $02 ;if so, we\'ve
49 bne copybyte ;entire screen
52 conway: lda #$df ;apply conway rules
53 sta $01 ;reset the pointer
54 sta $03 ;to $#01df/$#07df
55 lda #$01 ;($200 - $21)
59 onecell: lda #$00 ;process one cell
66 chkleft: tax ;check to see
67 lda $01 ;if we\'re at the
73 leftcells: ldy #$00 ;upper-left cell
79 ldy #$40 ;lower-left cell
82 chkright: tax ;check to see
83 lda $01 ;if we\'re at the
89 rightcells: ldy #$02 ;upper-right cell
95 ldy #$42 ;lower-right cell
98 evaluate: ldx #$01 ;evaluate total
99 ldy #$21 ;for current cell
103 cmp #$02 ;2 = alive if
104 bne storex ;c = alive
108 storex: txa ;store to screen
110 jsr inc0103 ;move to next cell
111 conwayloop: cmp #$e0 ;if not last cell,
112 bne onecell ;process next cell
116 jmp starttick ;run next tick
119 inc0103: lda $01 ;increment $01
120 cmp #$ff ;and $03 as 16-bit
121 bne onlyinc01 ;pointers