diff --git a/documentation.json b/documentation.json index f318501..b12dc6d 100644 --- a/documentation.json +++ b/documentation.json @@ -42,6 +42,7 @@ }, "Logic" : { "Luacontroller" : "mesecons_luacontroller/doc/luacontroller", + "Microcontroller" : "mesecons_microcontroller/doc/microcontroler", "FPGA" : "mesecons_fpga/doc/fpga", "FPGA Programmer" : "mesecons_fpga/doc/programmer", "Torch" : "mesecons_torch/doc/torch", diff --git a/mesecons_microcontroller/doc/microcontroller/description.html b/mesecons_microcontroller/doc/microcontroller/description.html new file mode 100644 index 0000000..af1e5c3 --- /dev/null +++ b/mesecons_microcontroller/doc/microcontroller/description.html @@ -0,0 +1,64 @@ + +

The Microcontroller is a semi-advanced programmable component with a persistent +256 bit EEPROM memory.

+

Warning: This device is largely considered deprecated and might contain bugs. It +is recommended to use a Luacontroller instead.

+

Detailed documentation can be found below:

+ diff --git a/mesecons_microcontroller/doc/microcontroller/description.md b/mesecons_microcontroller/doc/microcontroller/description.md new file mode 100644 index 0000000..a723537 --- /dev/null +++ b/mesecons_microcontroller/doc/microcontroller/description.md @@ -0,0 +1,59 @@ + + +The Microcontroller is a semi-advanced programmable component with a persistent +256 bit EEPROM memory. + +Warning: This device is largely considered deprecated and might contain bugs. It +is recommended to use a Luacontroller instead. + +Detailed documentation can be found below: + +* The Microcontroller's code is executed whenever any of the following events + happens: + * The Microcontroller is programmed. In this case the EEPROM and ports are all + reset to `0` before. + * An incoming signal changes its state. + * An `after` event happens (see command `after` below). +* There are 4 I/O ports (ABCD) and 256 EEPROM bits (1 to 256). +* The code consists of a sequence of commands. +* Everything after `:` is a comment. +* Strings are enclosed in `"`s. +* Spaces and tabs outside of strings are ignored. +* Basic command syntax: + ``` + command_name`(`param1`,` param2`,` ...`)` + ``` +* Commands: + * `if(condition) commands [> else_commands];`: + Evaluates the given condition and takes the corresponding branch. + The else branch is optional (as indicated by the `[` and `]`). The `>` is part + of the syntax and indicates the start of the else branch. The `;` marks the + end of the if command. + * `on(port1, port2, ...)`: + Sets the given ports to `1`. + * `off(port1, port2, ...)`: + Sets the given ports to `0`. + * `print("string" or codition, ...)`: + Evaluates the conditions and prints the concatenation of all params to stdout + (only useful in singleplayer). + * `after(time, "more commands")`: + Executes the commands in the string after the given time in seconds. + There can only be one waiting `after` event at once. + Warning: This is not reliable, ie. `minetest.after` is used. + * `sbi(port_or_eeprom, condition)`: + Evaluates the condition and sets the port or EEPROM bit to the resulting value. + Note: EEPROM indices don't use `#` here, ie. it's `sbi(1, #2)`, not `sbi(#1, #2)`. +* Conditions (sorted by descending precedence; they are all evaluated from left + to right): + * `0`, `1`: constant + * `A`, ..., `D`: value of a port. Takes writes that already happened during the + current execution into account. + * `#1`, ..., `#256`: value of an EEPROM bit. Takes writes that already happened + during the current execution into account. + * `!condition`: negation (can only be applied once, ie. not `!!1`) + * `condition1 = condition2`: XNOR (equality) + * `condition1 op condition2` where `op` is one of: + * `&`: AND + * `|`: OR + * `~`: XOR (inequality) + * Note: Explicit precedence using parentheses is not supported. diff --git a/mesecons_microcontroller/doc/microcontroller/preview.png b/mesecons_microcontroller/doc/microcontroller/preview.png new file mode 100644 index 0000000..cf15882 Binary files /dev/null and b/mesecons_microcontroller/doc/microcontroller/preview.png differ diff --git a/mesecons_microcontroller/doc/microcontroller/recipe.png b/mesecons_microcontroller/doc/microcontroller/recipe.png new file mode 100644 index 0000000..bf6ebd3 Binary files /dev/null and b/mesecons_microcontroller/doc/microcontroller/recipe.png differ diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index d28df2b..b3b7e36 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -122,7 +122,7 @@ minetest.register_node(nodename, { elseif fields.bnand then fields.code = "sbi(C, !A|!B) :A and B are inputs, C is output" elseif fields.btflop then - fields.code = "if(A)sbi(1,1);if(!A)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" + fields.code = "if(A)sbi(1,1);if(!A)sbi(B,!B)sbi(1,0); if(C)off(B); :A is input, B is output (Q), C is reset, toggles with falling edge" elseif fields.brsflop then fields.code = "if(A)on(C);if(B)off(C); :A is S (Set), B is R (Reset), C is output (R dominates)" end