]>
iEval git - clump.git/blob - cells.pl
8 sub send_memory_to_news
{
10 alu3 alu_select_a
, alu_select_a
, $address, $address, $address, flag_zero
, flag_zero
;
14 my ($address, $flag) = @_;
15 alu3 alu_zero
, alu_select_f
, 0, 0, $address, $flag, flag_zero
;
20 sub read_write_two_ways
{
22 my $memory = $news + 1;
23 send_memory_to_news
0;
24 alu3 alu_zero
, alu_select_f
, 0, 0, $memory, flag_news
($news), flag_zero
;
25 send_memory_to_news
0;
26 alu3 aluc_addAF
, alus_addAF
, $memory, 0, $memory, flag_news
($news + 1), $flag_F;
27 flag_to_memory
$memory + 1, $flag_F;
32 # write memory 0 to news
33 # read from news direction 0 into memory 1
34 # write memory 0 to news
35 # read from news direction 1, add to memory 1, write into memory 1 and flag F
36 # write flag F to memory 2
37 read_write_two_ways
(0);
39 # write memory 0 to news
40 # read from news direction 2 into memory 3
41 # write memory 0 to news
42 # read from news direction 3, add to memory 3, write into memory 3 and flag F
43 # write flag F to memory 4
44 read_write_two_ways
(2);
46 # write memory 0 to news
47 # read from news direction 4 into memory 5
48 # write memory 0 to news
49 # read from news direction 5, add to memory 5, write into memory 5 and flag F
50 # write flag F to memory 6
51 read_write_two_ways
(4);
53 # write memory 0 to news
54 # read from news direction 6 into memory 7
55 # write memory 0 to news
56 # read from news direction 7, add to memory 7, write into memory 7 and flag F
57 # write flag F to memory 8
58 read_write_two_ways
(6);
60 # read from memory 1, add to memory 3, write into memory 1 and flag F
62 # read from memory 2, add to memory 4 and flag F, write into memory 2 and flag F
63 addC
2, 4, 2, $flag_F;
64 # write flag F to memory 3
65 flag_to_memory
3, $flag_F;
67 # read from memory 5, add to memory 7, write into memory 5 and flag F
69 # read from memory 6, add to memory 8 and flag F, write into memory 6 and flag F
70 addC
6, 8, 6, $flag_F;
71 # write flag F to memory 7
72 flag_to_memory
7, $flag_F;
74 # read from memory 1, add to memory 5, write into memory 1 and flag F
76 # read from memory 2, add to memory 6 and flag F, write into memory 2 and flag F
77 addC
2, 6, 2, $flag_F;
78 # read from memory 3, or with memory 7 and flag F, write into flag F
79 alu3 alu_or
, alu_select_a
, 3, 7, 3, $flag_F, $flag_F;
81 # should a new cell be born here? (do we have 3 neighbours?)
82 sub alu_birth
{ alu_of_function
{; $a && $b && !$_ } }
84 # should a living cell survive here? (do we have 2 or 3 neighbours?)
85 sub alu_survival
{ alu_of_function
{; $a && !$_ } }
87 # compute the state of this cell at the next tick
88 sub alu_step
{ alu_of_function
{; $_ & ($a | $b) } }
90 # read from memory 1, and with memory 2 and not F, write into memory 1 (= birth-p)
91 alu3 alu_zero
, alu_birth
, 1, 2, 1, $flag_F, flag_zero
;
92 # read from memory 2, and with flag not F, write into flag F (= survive-p)
93 alu3 alu_survival
, alu_select_a
, 2, 0, 2, $flag_F, $flag_F;
94 # read from memory 0, memory 1, and flag F, write F and (mem0 or mem1) into memory 0
95 alu3 alu_zero
, alu_step
, 0, 1, 0, $flag_F, $flag_F; # also zeroes out flag F
98 # say 'Press enter to continue:';
100 # say 'Pressed, continuing';
114 # start with a blinker
119 store
0, flag_zero
, 0, 0;
This page took 0.047052 seconds and 4 git commands to generate.