Skip to content

Commit d52eac5

Browse files
authored
Add documentation for Microcontroller (#603)
1 parent e2c8a81 commit d52eac5

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed

documentation.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"Logic" : {
4444
"Luacontroller" : "mesecons_luacontroller/doc/luacontroller",
45+
"Microcontroller" : "mesecons_microcontroller/doc/microcontroler",
4546
"FPGA" : "mesecons_fpga/doc/fpga",
4647
"FPGA Programmer" : "mesecons_fpga/doc/programmer",
4748
"Torch" : "mesecons_torch/doc/torch",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!-- Generate `description.html` from this by using `$ md2html -o description.html description.md`. -->
2+
<p>The Microcontroller is a semi-advanced programmable component with a persistent
3+
256 bit EEPROM memory.</p>
4+
<p>Warning: This device is largely considered deprecated and might contain bugs. It
5+
is recommended to use a Luacontroller instead.</p>
6+
<p>Detailed documentation can be found below:</p>
7+
<ul>
8+
<li>The Microcontroller's code is executed whenever any of the following events
9+
happens:<ul>
10+
<li>The Microcontroller is programmed. In this case the EEPROM and ports are all
11+
reset to <code>0</code> before.</li>
12+
<li>An incoming signal changes its state.</li>
13+
<li>An <code>after</code> event happens (see command <code>after</code> below).</li>
14+
</ul>
15+
</li>
16+
<li>There are 4 I/O ports (ABCD) and 256 EEPROM bits (1 to 256).</li>
17+
<li>The code consists of a sequence of commands.</li>
18+
<li>Everything after <code>:</code> is a comment.</li>
19+
<li>Strings are enclosed in <code>&quot;</code>s.</li>
20+
<li>Spaces and tabs outside of strings are ignored.</li>
21+
<li>Basic command syntax:<pre><code> command_name`(`param1`,` param2`,` ...`)`
22+
</code></pre>
23+
</li>
24+
<li>Commands:<ul>
25+
<li><code>if(condition) commands [&gt; else_commands];</code>:
26+
Evaluates the given condition and takes the corresponding branch.
27+
The else branch is optional (as indicated by the <code>[</code> and <code>]</code>). The <code>&gt;</code> is part
28+
of the syntax and indicates the start of the else branch. The <code>;</code> marks the
29+
end of the if command.</li>
30+
<li><code>on(port1, port2, ...)</code>:
31+
Sets the given ports to <code>1</code>.</li>
32+
<li><code>off(port1, port2, ...)</code>:
33+
Sets the given ports to <code>0</code>.</li>
34+
<li><code>print(&quot;string&quot; or codition, ...)</code>:
35+
Evaluates the conditions and prints the concatenation of all params to stdout
36+
(only useful in singleplayer).</li>
37+
<li><code>after(time, &quot;more commands&quot;)</code>:
38+
Executes the commands in the string after the given time in seconds.
39+
There can only be one waiting <code>after</code> event at once.
40+
Warning: This is not reliable, ie. <code>minetest.after</code> is used.</li>
41+
<li><code>sbi(port_or_eeprom, condition)</code>:
42+
Evaluates the condition and sets the port or EEPROM bit to the resulting value.
43+
Note: EEPROM indices don't use <code>#</code> here, ie. it's <code>sbi(1, #2)</code>, not <code>sbi(#1, #2)</code>.</li>
44+
</ul>
45+
</li>
46+
<li>Conditions (sorted by descending precedence; they are all evaluated from left
47+
to right):<ul>
48+
<li><code>0</code>, <code>1</code>: constant</li>
49+
<li><code>A</code>, ..., <code>D</code>: value of a port. Takes writes that already happened during the
50+
current execution into account.</li>
51+
<li><code>#1</code>, ..., <code>#256</code>: value of an EEPROM bit. Takes writes that already happened
52+
during the current execution into account.</li>
53+
<li><code>!condition</code>: negation (can only be applied once, ie. not <code>!!1</code>)</li>
54+
<li><code>condition1 = condition2</code>: XNOR (equality)</li>
55+
<li><code>condition1 op condition2</code> where <code>op</code> is one of:<ul>
56+
<li><code>&amp;</code>: AND</li>
57+
<li><code>|</code>: OR</li>
58+
<li><code>~</code>: XOR (inequality)</li>
59+
</ul>
60+
</li>
61+
<li>Note: Explicit precedence using parentheses is not supported.</li>
62+
</ul>
63+
</li>
64+
</ul>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!-- Generate `description.html` from this by using `$ md2html -o description.html description.md`. -->
2+
3+
The Microcontroller is a semi-advanced programmable component with a persistent
4+
256 bit EEPROM memory.
5+
6+
Warning: This device is largely considered deprecated and might contain bugs. It
7+
is recommended to use a Luacontroller instead.
8+
9+
Detailed documentation can be found below:
10+
11+
* The Microcontroller's code is executed whenever any of the following events
12+
happens:
13+
* The Microcontroller is programmed. In this case the EEPROM and ports are all
14+
reset to `0` before.
15+
* An incoming signal changes its state.
16+
* An `after` event happens (see command `after` below).
17+
* There are 4 I/O ports (ABCD) and 256 EEPROM bits (1 to 256).
18+
* The code consists of a sequence of commands.
19+
* Everything after `:` is a comment.
20+
* Strings are enclosed in `"`s.
21+
* Spaces and tabs outside of strings are ignored.
22+
* Basic command syntax:
23+
```
24+
command_name`(`param1`,` param2`,` ...`)`
25+
```
26+
* Commands:
27+
* `if(condition) commands [> else_commands];`:
28+
Evaluates the given condition and takes the corresponding branch.
29+
The else branch is optional (as indicated by the `[` and `]`). The `>` is part
30+
of the syntax and indicates the start of the else branch. The `;` marks the
31+
end of the if command.
32+
* `on(port1, port2, ...)`:
33+
Sets the given ports to `1`.
34+
* `off(port1, port2, ...)`:
35+
Sets the given ports to `0`.
36+
* `print("string" or codition, ...)`:
37+
Evaluates the conditions and prints the concatenation of all params to stdout
38+
(only useful in singleplayer).
39+
* `after(time, "more commands")`:
40+
Executes the commands in the string after the given time in seconds.
41+
There can only be one waiting `after` event at once.
42+
Warning: This is not reliable, ie. `minetest.after` is used.
43+
* `sbi(port_or_eeprom, condition)`:
44+
Evaluates the condition and sets the port or EEPROM bit to the resulting value.
45+
Note: EEPROM indices don't use `#` here, ie. it's `sbi(1, #2)`, not `sbi(#1, #2)`.
46+
* Conditions (sorted by descending precedence; they are all evaluated from left
47+
to right):
48+
* `0`, `1`: constant
49+
* `A`, ..., `D`: value of a port. Takes writes that already happened during the
50+
current execution into account.
51+
* `#1`, ..., `#256`: value of an EEPROM bit. Takes writes that already happened
52+
during the current execution into account.
53+
* `!condition`: negation (can only be applied once, ie. not `!!1`)
54+
* `condition1 = condition2`: XNOR (equality)
55+
* `condition1 op condition2` where `op` is one of:
56+
* `&`: AND
57+
* `|`: OR
58+
* `~`: XOR (inequality)
59+
* Note: Explicit precedence using parentheses is not supported.
Loading
Loading

mesecons_microcontroller/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ minetest.register_node(nodename, {
122122
elseif fields.bnand then
123123
fields.code = "sbi(C, !A|!B) :A and B are inputs, C is output"
124124
elseif fields.btflop then
125-
fields.code = "if(A)sbi(1,1);if(!A&#1)sbi(B,!B)sbi(1,0); if(C)off(B,1); :A is input, B is output (Q), C is reset, toggles with falling edge"
125+
fields.code = "if(A)sbi(1,1);if(!A&#1)sbi(B,!B)sbi(1,0); if(C)off(B); :A is input, B is output (Q), C is reset, toggles with falling edge"
126126
elseif fields.brsflop then
127127
fields.code = "if(A)on(C);if(B)off(C); :A is S (Set), B is R (Reset), C is output (R dominates)"
128128
end

0 commit comments

Comments
 (0)