├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md └── workflows │ ├── autoPublish.yml │ ├── lint.yml │ └── publish.yml ├── .lua-format ├── .scripts ├── upload.sh └── zip_mod.sh ├── FAL_REFERENCE.docx ├── FAL_REFERENCE.pdf ├── LICENSE ├── OLD_FAL_REFERENCE.pdf ├── bitwise.lua ├── changelog.txt ├── compiler.lua ├── constants.lua ├── control.lua ├── data.lua ├── graphics ├── black.png ├── cancel.png ├── copy.png ├── draft.png ├── grey.png ├── info.png ├── input.png ├── microchip.png ├── microchip_large.png ├── next.png ├── play.png ├── ram.png ├── signal_halt.png ├── signal_jump.png ├── signal_run.png ├── signal_sleep.png ├── signal_step.png ├── stop.png └── test.png ├── info.json ├── locale ├── en │ └── microcontroller.cfg ├── fr │ └── microcontroller.cfg ├── nl │ └── microcontroller.cfg ├── ru │ └── microcontroller.cfg ├── tr │ └── microcontroller.cfg └── uk │ └── microcontroller.cfg ├── microcontroller.lua ├── prototypes └── style.lua ├── readme.md ├── scenarios └── examples │ ├── blueprint.zip │ ├── control.lua │ ├── image.png │ ├── info.json │ └── script.dat ├── settings.lua ├── stdlib ├── area │ ├── area.lua │ ├── chunk.lua │ ├── position.lua │ └── tile.lua ├── config │ └── config.lua ├── core.lua ├── data │ ├── data.lua │ └── recipe.lua ├── entity │ ├── entity.lua │ └── inventory.lua ├── event │ ├── event.lua │ └── time.lua ├── game.lua ├── gui │ └── gui.lua ├── log │ └── logger.lua ├── math.lua ├── string.lua ├── surface.lua ├── table.lua ├── time.lua └── trains │ └── trains.lua └── thumbnail.png /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | 12 | [*.{lua,lua2p,sh,cmd,can}] 13 | indent_style = tab 14 | insert_final_newline = true 15 | 16 | [*.{txt,yml,json}] 17 | indent_style = space 18 | indent_size = 2 19 | insert_final_newline = false 20 | 21 | [*.cfg] 22 | indent_style = space 23 | indent_size = 2 24 | insert_final_newline = true 25 | trim_trailing_whitespace = false 26 | 27 | [*.md] 28 | indent_style = tab 29 | indent_size = 2 30 | insert_final_newline = false 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: ZwerOxotnik 7 | 8 | --- 9 | 10 | Please drop the `factorio-current.log` file or `factorio-previous.log` here 11 | 12 | **Describe the bug** 13 | 14 | 15 | **Steps to reproduce** 16 | 1. 17 | 2. 18 | 3. 19 | 20 | **Expected behavior** 21 | 22 | 23 | **Screenshots/Videos (If you have any)** 24 | 25 | 26 | 27 | **Additional Information** 28 | Add any other context about the problem here? 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE REQUEST]" 5 | labels: feature request 6 | assignees: ZwerOxotnik 7 | 8 | --- 9 | 10 | **Is your feature request related to a issue? Please describe.** 11 | 12 | 13 | **Describe the suggestion (Use a lot of details if it is complex)** 14 | 15 | 16 | **Screenshots/Videos (If you have any that will help us)** 17 | 18 | 19 | **Additional Information** 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: You have a question that you would like answered 4 | title: "[QUESTION]" 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Please put your question below** 11 | -------------------------------------------------------------------------------- /.github/workflows/autoPublish.yml: -------------------------------------------------------------------------------- 1 | name: Auto publish 2 | 3 | on: 4 | push: 5 | paths: 6 | - 'info.json' # Triggers only if the mod info file is updated 7 | branches: 8 | - main 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository and submodules 15 | uses: actions/checkout@v3 16 | with: 17 | submodules: recursive 18 | - name: get mod_version 19 | id: mod_version 20 | uses: notiz-dev/github-action-json-property@release 21 | with: 22 | path: 'info.json' 23 | prop_path: 'version' 24 | - name: get factorio_version 25 | id: factorio_version 26 | uses: notiz-dev/github-action-json-property@release 27 | with: 28 | path: 'info.json' 29 | prop_path: 'factorio_version' 30 | - name: get mod name 31 | id: mod_name 32 | uses: notiz-dev/github-action-json-property@release 33 | with: 34 | path: 'info.json' 35 | prop_path: 'name' 36 | - name: Zip mod 37 | run: bash ./.scripts/zip_mod.sh 38 | - name: Upload the mod on mods.factorio.com 39 | env: 40 | FACTORIO_MOD_API_KEY: ${{ secrets.FACTORIO_MOD_API_KEY }} 41 | run: bash ./.scripts/upload.sh 42 | - uses: marvinpinto/action-automatic-releases@latest 43 | id: aar 44 | with: 45 | automatic_release_tag: "${{steps.mod_version.outputs.prop}}" 46 | title: "For factorio ${{steps.factorio_version.outputs.prop}}" 47 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 48 | prerelease: false 49 | files: | 50 | ./${{steps.mod_name.outputs.prop}}_${{steps.version.outputs.prop}}.zip -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | 6 | name: Lint 7 | jobs: 8 | lint: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: lint 13 | uses: Roang-zero1/factorio-mod-luacheck@master 14 | with: 15 | luacheckrc_url: https://github.com/Nexela/Factorio-luacheckrc/raw/master/.luacheckrc 16 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: push 2 | name: Publish 3 | jobs: 4 | publish: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout repository and submodules 8 | uses: actions/checkout@v2 9 | with: 10 | submodules: recursive 11 | - name: Publish Mod 12 | uses: shanemadden/factorio-mod-portal-publish@stable 13 | env: 14 | FACTORIO_PASSWORD: ${{ secrets.FACTORIO_PASSWORD }} 15 | FACTORIO_USER: ${{ secrets.FACTORIO_USER }} 16 | -------------------------------------------------------------------------------- /.lua-format: -------------------------------------------------------------------------------- 1 | column_limit: &1 120 2 | indent_width: 1 3 | use_tab: true 4 | tab_width: 4 5 | continuation_indent_width: 4 6 | spaces_before_call: 0 7 | keep_simple_control_block_one_line: false 8 | keep_simple_function_one_line: false 9 | align_args: false 10 | break_after_functioncall_lp: false 11 | break_before_functioncall_rp: false 12 | align_parameter: false 13 | chop_down_parameter: false 14 | break_after_functiondef_lp: false 15 | break_before_functiondef_rp: true 16 | align_table_field: false 17 | break_after_table_lb: true 18 | break_before_table_rb: true 19 | chop_down_table: false 20 | chop_down_kv_table: true 21 | table_sep: "," 22 | extra_sep_at_table_end: false 23 | column_table_limit: *1 24 | break_after_operator: true 25 | double_quote_to_single_quote: false 26 | single_quote_to_double_quote: true 27 | -------------------------------------------------------------------------------- /.scripts/upload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | (set -o igncr) 2>/dev/null && set -o igncr; # This comment is required. 3 | ### The above line ensures that the script can be run on Cygwin/Linux even with Windows CRNL. 4 | ### Run this script on GitHub after zipping the mod to upload the mod on mods.factorio.com 5 | ### This a modified version of https://github.com/Penguin-Spy/factorio-mod-portal-publish/blob/5c669dc60672e6293afd5b1913a0c8475c5490c0/entrypoint.sh 6 | ### You can generate your FACTORIO_MOD_API_KEY on https://factorio.com/create-api-key 7 | 8 | 9 | main() { 10 | ### Check commands 11 | local has_errors=false 12 | if ! command -v jq &> /dev/null; then 13 | echo "Please install jq https://stedolan.github.io/jq/" 14 | local has_errors=true 15 | fi 16 | if [ $has_errors = true ] ; then 17 | exit 1 18 | fi 19 | 20 | 21 | ### Get mod name and version from info.json 22 | ### https://stedolan.github.io/jq/ 23 | local MOD_VERSION=$(jq -r '.version' info.json) 24 | local MOD_NAME=$(jq -r '.name' info.json) 25 | 26 | 27 | # Validate the version string we're building 28 | if ! echo "${MOD_VERSION}" | grep -P --quiet '^\d+\.\d+\.\d+$'; then 29 | echo "Incorrect version pattern, needs to be %u.%u.%u (e.q., 0.1.0)" 30 | exit 1 31 | fi 32 | 33 | 34 | # Get an upload url for the mod 35 | local URL_RESULT=$(curl -s -d "mod=${MOD_NAME}" -H "Authorization: Bearer ${FACTORIO_MOD_API_KEY}" https://mods.factorio.com/api/v2/mods/releases/init_upload) 36 | local UPLOAD_URL=$(echo "${URL_RESULT}" | jq -r '.upload_url') 37 | if [[ "${UPLOAD_URL}" == "null" ]] || [[ -z "${UPLOAD_URL}" ]]; then 38 | echo "Couldn't get an upload url, failed" 39 | local ERROR=$(echo "${URL_RESULT}" | jq -r '.error') 40 | local MESSAGE=$(echo "${URL_RESULT}" | jq -r '.message // empty') 41 | echo "${ERROR}: ${MESSAGE}" 42 | exit 1 43 | fi 44 | 45 | 46 | # Upload the file 47 | local UPLOAD_RESULT=$(curl -s -F "file=@${MOD_NAME}_${MOD_VERSION}.zip" "${UPLOAD_URL}") 48 | 49 | # The success attribute only appears on successful uploads 50 | local SUCCESS=$(echo "${UPLOAD_RESULT}" | jq -r '.success') 51 | if [[ "${SUCCESS}" == "null" ]] || [[ -z "${SUCCESS}" ]]; then 52 | echo "Upload failed" 53 | local ERROR=$(echo "${UPLOAD_RESULT}" | jq -r '.error') 54 | local MESSAGE=$(echo "${UPLOAD_RESULT}" | jq -r '.message // empty') 55 | echo "${ERROR}: ${MESSAGE}" 56 | exit 1 57 | fi 58 | 59 | echo "Upload of ${MOD_NAME}_${MOD_VERSION}.zip completed" 60 | } 61 | main 62 | -------------------------------------------------------------------------------- /.scripts/zip_mod.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | (set -o igncr) 2>/dev/null && set -o igncr; # This comment is required. 3 | ### The above line ensures that the script can be run on Cygwin/Linux even with Windows CRNL. 4 | ### Run this script after updating the mod to prepare a zip of it. 5 | 6 | main() { 7 | ### Check commands 8 | if ! command -v git &> /dev/null; then 9 | echo "Please install/use git https://git-scm.com/downloads" 10 | fi 11 | local has_errors=false 12 | if ! command -v jq &> /dev/null; then 13 | echo "Please install jq https://stedolan.github.io/jq/" 14 | local has_errors=true 15 | fi 16 | if ! command -v 7z &> /dev/null; then 17 | echo "Please install 7-Zip https://www.7-zip.org/download.html" 18 | local has_errors=true 19 | fi 20 | if [ $has_errors = true ] ; then 21 | exit 1 22 | fi 23 | 24 | 25 | ### mod_folder is a mod directory with info.json 26 | local init_dir=`pwd` 27 | 28 | 29 | ### Find info.json 30 | local SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 31 | local infojson_exists=false 32 | if [[ -s "$SCRIPT_DIR/info.json" ]]; then 33 | infojson_exists=true 34 | mod_folder=$SCRIPT_DIR 35 | else 36 | cd $SCRIPT_DIR 37 | cd .. 38 | if [[ -s "$PWD/info.json" ]]; then 39 | infojson_exists=true 40 | mod_folder=$PWD 41 | elif [[ -s "$init_dir/info.json" ]]; then 42 | infojson_exists=true 43 | mod_folder=$init_dir 44 | fi 45 | fi 46 | 47 | 48 | if [ $infojson_exists = false ] ; then 49 | echo "There's no info.json" 50 | exit 1 51 | fi 52 | cd "$mod_folder/" 53 | echo "Target folder: ${mod_folder}" 54 | 55 | 56 | ### Get mod name and version from info.json 57 | ### https://stedolan.github.io/jq/ 58 | local MOD_NAME=$(jq -r '.name' info.json) 59 | local MOD_VERSION=$(jq -r '.version' info.json) 60 | 61 | 62 | # Validate the version string we're building 63 | if ! echo "${MOD_VERSION}" | grep -P --quiet '^\d+\.\d+\.\d+$'; then 64 | echo "Incorrect version pattern, needs to be %u.%u.%u (e.q., 0.1.0)" 65 | exit 1 66 | fi 67 | 68 | 69 | ### Prepare zip for Factorio native use and mod portal 70 | ### https://www.7-zip.org/download.html 71 | local name="${MOD_NAME}_${MOD_VERSION}" 72 | if command -v git &> /dev/null; then 73 | git clean -xdf 74 | fi 75 | 7z a -xr'!.*' "${mod_folder}/${name}.zip" "${mod_folder}" 76 | } 77 | main 78 | -------------------------------------------------------------------------------- /FAL_REFERENCE.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZwerOxotnik/m-microcontroller/0fb076ce1da4e43087d90f1a55fc98de706ecc96/FAL_REFERENCE.docx -------------------------------------------------------------------------------- /FAL_REFERENCE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZwerOxotnik/m-microcontroller/0fb076ce1da4e43087d90f1a55fc98de706ecc96/FAL_REFERENCE.pdf -------------------------------------------------------------------------------- /OLD_FAL_REFERENCE.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZwerOxotnik/m-microcontroller/0fb076ce1da4e43087d90f1a55fc98de706ecc96/OLD_FAL_REFERENCE.pdf -------------------------------------------------------------------------------- /bitwise.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 3 | LUA MODULE 4 | 5 | bit.numberlua - Bitwise operations implemented in pure Lua as numbers, 6 | with Lua 5.2 'bit32' and (LuaJIT) LuaBitOp 'bit' compatibility interfaces. 7 | 8 | SYNOPSIS 9 | 10 | local bit = require 'bit.numberlua' 11 | print(bit.band(0xff00ff00, 0x00ff00ff)) --> 0xffffffff 12 | 13 | -- Interface providing strong Lua 5.2 'bit32' compatibility 14 | local bit32 = require 'bit.numberlua'.bit32 15 | assert(bit32.band(-1) == 0xffffffff) 16 | 17 | -- Interface providing strong (LuaJIT) LuaBitOp 'bit' compatibility 18 | local bit = require 'bit.numberlua'.bit 19 | assert(bit.tobit(0xffffffff) == -1) 20 | 21 | DESCRIPTION 22 | 23 | This library implements bitwise operations entirely in Lua. 24 | This module is typically intended if for some reasons you don't want 25 | to or cannot install a popular C based bit library like BitOp 'bit' [1] 26 | (which comes pre-installed with LuaJIT) or 'bit32' (which comes 27 | pre-installed with Lua 5.2) but want a similar interface. 28 | 29 | This modules represents bit arrays as non-negative Lua numbers. [1] 30 | It can represent 32-bit bit arrays when Lua is compiled 31 | with lua_Number as double-precision IEEE 754 floating point. 32 | 33 | The module is nearly the most efficient it can be but may be a few times 34 | slower than the C based bit libraries and is orders or magnitude 35 | slower than LuaJIT bit operations, which compile to native code. Therefore, 36 | this library is inferior in performane to the other modules. 37 | 38 | The `xor` function in this module is based partly on Roberto Ierusalimschy's 39 | post in http://lua-users.org/lists/lua-l/2002-09/msg00134.html . 40 | 41 | The included BIT.bit32 and BIT.bit sublibraries aims to provide 100% 42 | compatibility with the Lua 5.2 "bit32" and (LuaJIT) LuaBitOp "bit" library. 43 | This compatbility is at the cost of some efficiency since inputted 44 | numbers are normalized and more general forms (e.g. multi-argument 45 | bitwise operators) are supported. 46 | 47 | STATUS 48 | 49 | WARNING: Not all corner cases have been tested and documented. 50 | Some attempt was made to make these similar to the Lua 5.2 [2] 51 | and LuaJit BitOp [3] libraries, but this is not fully tested and there 52 | are currently some differences. Addressing these differences may 53 | be improved in the future but it is not yet fully determined how to 54 | resolve these differences. 55 | 56 | The BIT.bit32 library passes the Lua 5.2 test suite (bitwise.lua) 57 | http://www.lua.org/tests/5.2/ . The BIT.bit library passes the LuaBitOp 58 | test suite (bittest.lua). However, these have not been tested on 59 | platforms with Lua compiled with 32-bit integer numbers. 60 | 61 | API 62 | 63 | BIT.tobit(x) --> z 64 | 65 | Similar to function in BitOp. 66 | 67 | BIT.tohex(x, n) 68 | 69 | Similar to function in BitOp. 70 | 71 | BIT.band(x, y) --> z 72 | 73 | Similar to function in Lua 5.2 and BitOp but requires two arguments. 74 | 75 | BIT.bor(x, y) --> z 76 | 77 | Similar to function in Lua 5.2 and BitOp but requires two arguments. 78 | 79 | BIT.bxor(x, y) --> z 80 | 81 | Similar to function in Lua 5.2 and BitOp but requires two arguments. 82 | 83 | BIT.bnot(x) --> z 84 | 85 | Similar to function in Lua 5.2 and BitOp. 86 | 87 | BIT.lshift(x, disp) --> z 88 | 89 | Similar to function in Lua 5.2 (warning: BitOp uses unsigned lower 5 bits of shift), 90 | 91 | BIT.rshift(x, disp) --> z 92 | 93 | Similar to function in Lua 5.2 (warning: BitOp uses unsigned lower 5 bits of shift), 94 | 95 | BIT.extract(x, field [, width]) --> z 96 | 97 | Similar to function in Lua 5.2. 98 | 99 | BIT.replace(x, v, field, width) --> z 100 | 101 | Similar to function in Lua 5.2. 102 | 103 | BIT.bswap(x) --> z 104 | 105 | Similar to function in Lua 5.2. 106 | 107 | BIT.rrotate(x, disp) --> z 108 | BIT.ror(x, disp) --> z 109 | 110 | Similar to function in Lua 5.2 and BitOp. 111 | 112 | BIT.lrotate(x, disp) --> z 113 | BIT.rol(x, disp) --> z 114 | 115 | Similar to function in Lua 5.2 and BitOp. 116 | 117 | BIT.arshift 118 | 119 | Similar to function in Lua 5.2 and BitOp. 120 | 121 | BIT.btest 122 | 123 | Similar to function in Lua 5.2 with requires two arguments. 124 | 125 | BIT.bit32 126 | 127 | This table contains functions that aim to provide 100% compatibility 128 | with the Lua 5.2 "bit32" library. 129 | 130 | bit32.arshift (x, disp) --> z 131 | bit32.band (...) --> z 132 | bit32.bnot (x) --> z 133 | bit32.bor (...) --> z 134 | bit32.btest (...) --> true | false 135 | bit32.bxor (...) --> z 136 | bit32.extract (x, field [, width]) --> z 137 | bit32.replace (x, v, field [, width]) --> z 138 | bit32.lrotate (x, disp) --> z 139 | bit32.lshift (x, disp) --> z 140 | bit32.rrotate (x, disp) --> z 141 | bit32.rshift (x, disp) --> z 142 | 143 | BIT.bit 144 | 145 | This table contains functions that aim to provide 100% compatibility 146 | with the LuaBitOp "bit" library (from LuaJIT). 147 | 148 | bit.tobit(x) --> y 149 | bit.tohex(x [,n]) --> y 150 | bit.bnot(x) --> y 151 | bit.bor(x1 [,x2...]) --> y 152 | bit.band(x1 [,x2...]) --> y 153 | bit.bxor(x1 [,x2...]) --> y 154 | bit.lshift(x, n) --> y 155 | bit.rshift(x, n) --> y 156 | bit.arshift(x, n) --> y 157 | bit.rol(x, n) --> y 158 | bit.ror(x, n) --> y 159 | bit.bswap(x) --> y 160 | 161 | DEPENDENCIES 162 | 163 | None (other than Lua 5.1 or 5.2). 164 | 165 | DOWNLOAD/INSTALLATION 166 | 167 | If using LuaRocks: 168 | luarocks install lua-bit-numberlua 169 | 170 | Otherwise, download . 171 | Alternately, if using git: 172 | git clone git://github.com/davidm/lua-bit-numberlua.git 173 | cd lua-bit-numberlua 174 | Optionally unpack: 175 | ./util.mk 176 | or unpack and install in LuaRocks: 177 | ./util.mk install 178 | 179 | REFERENCES 180 | 181 | [1] http://lua-users.org/wiki/FloatingPoint 182 | [2] http://www.lua.org/manual/5.2/ 183 | [3] http://bitop.luajit.org/ 184 | 185 | LICENSE 186 | 187 | (c) 2008-2011 David Manura. Licensed under the same terms as Lua (MIT). 188 | 189 | Permission is hereby granted, free of charge, to any person obtaining a copy 190 | of this software and associated documentation files (the "Software"), to deal 191 | in the Software without restriction, including without limitation the rights 192 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 193 | copies of the Software, and to permit persons to whom the Software is 194 | furnished to do so, subject to the following conditions: 195 | 196 | The above copyright notice and this permission notice shall be included in 197 | all copies or substantial portions of the Software. 198 | 199 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 200 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 201 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 202 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 203 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 204 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 205 | THE SOFTWARE. 206 | (end license) 207 | 208 | --]] 209 | 210 | local M = {_TYPE='module', _NAME='bit.numberlua', _VERSION='0.3.1.20120131'} 211 | 212 | local floor = math.floor 213 | 214 | local MOD = 2^32 215 | local MODM = MOD-1 216 | 217 | local function memoize(f) 218 | local mt = {} 219 | local t = setmetatable({}, mt) 220 | function mt:__index(k) 221 | local v = f(k); t[k] = v 222 | return v 223 | end 224 | return t 225 | end 226 | 227 | local function make_bitop_uncached(t, m) 228 | local function bitop(a, b) 229 | local res,p = 0,1 230 | while a ~= 0 and b ~= 0 do 231 | local am, bm = a%m, b%m 232 | res = res + t[am][bm]*p 233 | a = (a - am) / m 234 | b = (b - bm) / m 235 | p = p*m 236 | end 237 | res = res + (a+b)*p 238 | return res 239 | end 240 | return bitop 241 | end 242 | 243 | local function make_bitop(t) 244 | local op1 = make_bitop_uncached(t,2^1) 245 | local op2 = memoize(function(a) 246 | return memoize(function(b) 247 | return op1(a, b) 248 | end) 249 | end) 250 | return make_bitop_uncached(op2, 2^(t.n or 1)) 251 | end 252 | 253 | -- ok? probably not if running on a 32-bit int Lua number type platform 254 | function M.tobit(x) 255 | return x % 2^32 256 | end 257 | 258 | M.bxor = make_bitop {[0]={[0]=0,[1]=1},[1]={[0]=1,[1]=0}, n=4} 259 | local bxor = M.bxor 260 | 261 | function M.bnot(a) return MODM - a end 262 | local bnot = M.bnot 263 | 264 | function M.band(a,b) return ((a+b) - bxor(a,b))/2 end 265 | local band = M.band 266 | 267 | function M.bor(a,b) return MODM - band(MODM - a, MODM - b) end 268 | local bor = M.bor 269 | 270 | local lshift, rshift -- forward declare 271 | 272 | function M.rshift(a,disp) -- Lua5.2 insipred 273 | if disp < 0 then return lshift(a,-disp) end 274 | return floor(a % 2^32 / 2^disp) 275 | end 276 | rshift = M.rshift 277 | 278 | function M.lshift(a,disp) -- Lua5.2 inspired 279 | if disp < 0 then return rshift(a,-disp) end 280 | return (a * 2^disp) % 2^32 281 | end 282 | lshift = M.lshift 283 | 284 | function M.tohex(x, n) -- BitOp style 285 | n = n or 8 286 | local up 287 | if n <= 0 then 288 | if n == 0 then return '' end 289 | up = true 290 | n = - n 291 | end 292 | x = band(x, 16^n-1) 293 | return ('%0'..n..(up and 'X' or 'x')):format(x) 294 | end 295 | local tohex = M.tohex 296 | 297 | function M.extract(n, field, width) -- Lua5.2 inspired 298 | width = width or 1 299 | return band(rshift(n, field), 2^width-1) 300 | end 301 | local extract = M.extract 302 | 303 | function M.replace(n, v, field, width) -- Lua5.2 inspired 304 | width = width or 1 305 | local mask1 = 2^width-1 306 | v = band(v, mask1) -- required by spec? 307 | local mask = bnot(lshift(mask1, field)) 308 | return band(n, mask) + lshift(v, field) 309 | end 310 | local replace = M.replace 311 | 312 | function M.bswap(x) -- BitOp style 313 | local a = band(x, 0xff); x = rshift(x, 8) 314 | local b = band(x, 0xff); x = rshift(x, 8) 315 | local c = band(x, 0xff); x = rshift(x, 8) 316 | local d = band(x, 0xff) 317 | return lshift(lshift(lshift(a, 8) + b, 8) + c, 8) + d 318 | end 319 | local bswap = M.bswap 320 | 321 | function M.rrotate(x, disp) -- Lua5.2 inspired 322 | disp = disp % 32 323 | local low = band(x, 2^disp-1) 324 | return rshift(x, disp) + lshift(low, 32-disp) 325 | end 326 | local rrotate = M.rrotate 327 | 328 | function M.lrotate(x, disp) -- Lua5.2 inspired 329 | return rrotate(x, -disp) 330 | end 331 | local lrotate = M.lrotate 332 | 333 | M.rol = M.lrotate -- LuaOp inspired 334 | M.ror = M.rrotate -- LuaOp insipred 335 | 336 | 337 | function M.arshift(x, disp) -- Lua5.2 inspired 338 | local z = rshift(x, disp) 339 | if x >= 0x80000000 then z = z + lshift(2^disp-1, 32-disp) end 340 | return z 341 | end 342 | local arshift = M.arshift 343 | 344 | function M.btest(x, y) -- Lua5.2 inspired 345 | return band(x, y) ~= 0 346 | end 347 | 348 | -- 349 | -- Start Lua 5.2 "bit32" compat section. 350 | -- 351 | 352 | M.bit32 = {} -- Lua 5.2 'bit32' compatibility 353 | 354 | 355 | local function bit32_bnot(x) 356 | return (-1 - x) % MOD 357 | end 358 | M.bit32.bnot = bit32_bnot 359 | 360 | local function bit32_bxor(a, b, c, ...) 361 | local z 362 | if b then 363 | a = a % MOD 364 | b = b % MOD 365 | z = bxor(a, b) 366 | if c then 367 | z = bit32_bxor(z, c, ...) 368 | end 369 | return z 370 | elseif a then 371 | return a % MOD 372 | else 373 | return 0 374 | end 375 | end 376 | M.bit32.bxor = bit32_bxor 377 | 378 | local function bit32_band(a, b, c, ...) 379 | local z 380 | if b then 381 | a = a % MOD 382 | b = b % MOD 383 | z = ((a+b) - bxor(a,b)) / 2 384 | if c then 385 | z = bit32_band(z, c, ...) 386 | end 387 | return z 388 | elseif a then 389 | return a % MOD 390 | else 391 | return MODM 392 | end 393 | end 394 | M.bit32.band = bit32_band 395 | 396 | local function bit32_bor(a, b, c, ...) 397 | local z 398 | if b then 399 | a = a % MOD 400 | b = b % MOD 401 | z = MODM - band(MODM - a, MODM - b) 402 | if c then 403 | z = bit32_bor(z, c, ...) 404 | end 405 | return z 406 | elseif a then 407 | return a % MOD 408 | else 409 | return 0 410 | end 411 | end 412 | M.bit32.bor = bit32_bor 413 | 414 | function M.bit32.btest(...) 415 | return bit32_band(...) ~= 0 416 | end 417 | 418 | function M.bit32.lrotate(x, disp) 419 | return lrotate(x % MOD, disp) 420 | end 421 | 422 | function M.bit32.rrotate(x, disp) 423 | return rrotate(x % MOD, disp) 424 | end 425 | 426 | function M.bit32.lshift(x,disp) 427 | if disp > 31 or disp < -31 then return 0 end 428 | return lshift(x % MOD, disp) 429 | end 430 | 431 | function M.bit32.rshift(x,disp) 432 | if disp > 31 or disp < -31 then return 0 end 433 | return rshift(x % MOD, disp) 434 | end 435 | 436 | function M.bit32.arshift(x,disp) 437 | x = x % MOD 438 | if disp >= 0 then 439 | if disp > 31 then 440 | return (x >= 0x80000000) and MODM or 0 441 | else 442 | local z = rshift(x, disp) 443 | if x >= 0x80000000 then z = z + lshift(2^disp-1, 32-disp) end 444 | return z 445 | end 446 | else 447 | return lshift(x, -disp) 448 | end 449 | end 450 | 451 | function M.bit32.extract(x, field, ...) 452 | local width = ... or 1 453 | if field < 0 or field > 31 or width < 0 or field+width > 32 then error 'out of range' end 454 | x = x % MOD 455 | return extract(x, field, ...) 456 | end 457 | 458 | function M.bit32.replace(x, v, field, ...) 459 | local width = ... or 1 460 | if field < 0 or field > 31 or width < 0 or field+width > 32 then error 'out of range' end 461 | x = x % MOD 462 | v = v % MOD 463 | return replace(x, v, field, ...) 464 | end 465 | 466 | 467 | -- 468 | -- Start LuaBitOp "bit" compat section. 469 | -- 470 | 471 | M.bit = {} -- LuaBitOp "bit" compatibility 472 | 473 | function M.bit.tobit(x) 474 | x = x % MOD 475 | if x >= 0x80000000 then x = x - MOD end 476 | return x 477 | end 478 | local bit_tobit = M.bit.tobit 479 | 480 | function M.bit.tohex(x, ...) 481 | return tohex(x % MOD, ...) 482 | end 483 | 484 | function M.bit.bnot(x) 485 | return bit_tobit(bnot(x % MOD)) 486 | end 487 | 488 | local function bit_bor(a, b, c, ...) 489 | if c then 490 | return bit_bor(bit_bor(a, b), c, ...) 491 | elseif b then 492 | return bit_tobit(bor(a % MOD, b % MOD)) 493 | else 494 | return bit_tobit(a) 495 | end 496 | end 497 | M.bit.bor = bit_bor 498 | 499 | local function bit_band(a, b, c, ...) 500 | if c then 501 | return bit_band(bit_band(a, b), c, ...) 502 | elseif b then 503 | return bit_tobit(band(a % MOD, b % MOD)) 504 | else 505 | return bit_tobit(a) 506 | end 507 | end 508 | M.bit.band = bit_band 509 | 510 | local function bit_bxor(a, b, c, ...) 511 | if c then 512 | return bit_bxor(bit_bxor(a, b), c, ...) 513 | elseif b then 514 | return bit_tobit(bxor(a % MOD, b % MOD)) 515 | else 516 | return bit_tobit(a) 517 | end 518 | end 519 | M.bit.bxor = bit_bxor 520 | 521 | function M.bit.lshift(x, n) 522 | return bit_tobit(lshift(x % MOD, n % 32)) 523 | end 524 | 525 | function M.bit.rshift(x, n) 526 | return bit_tobit(rshift(x % MOD, n % 32)) 527 | end 528 | 529 | function M.bit.arshift(x, n) 530 | return bit_tobit(arshift(x % MOD, n % 32)) 531 | end 532 | 533 | function M.bit.rol(x, n) 534 | return bit_tobit(lrotate(x % MOD, n % 32)) 535 | end 536 | 537 | function M.bit.ror(x, n) 538 | return bit_tobit(rrotate(x % MOD, n % 32)) 539 | end 540 | 541 | function M.bit.bswap(x) 542 | return bit_tobit(bswap(x % MOD)) 543 | end 544 | 545 | return M -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------------------------- 2 | Version: 0.12.1 3 | Date: 27. 10. 2024 4 | Bugfixes: 5 | - Fixed localization for recipes 6 | --------------------------------------------------------------------------------------------------- 7 | Version: 0.12.0 8 | Date: 22. 10. 2024 9 | Changes: 10 | - Updated for Factorio 2.0 11 | --------------------------------------------------------------------------------------------------- 12 | Version: 0.11.2 13 | Date: 06. 05. 2023 14 | Bugfixes: 15 | - Improved data stability at start 16 | --------------------------------------------------------------------------------------------------- 17 | Version: 0.11.1 18 | Date: 13. 03. 2023 19 | Locale: 20 | - Updated French translation (contributed by https://github.com/XZ1048576 ) 21 | - Added Turkish translation (contributed by @oncelx on crowdin) 22 | --------------------------------------------------------------------------------------------------- 23 | Version: 0.11.0 24 | Date: 03. 03. 2023 25 | Locale: 26 | - Added French translation (contributed by https://github.com/XZ1048576 ) 27 | Features: 28 | - Added technologies to increase maximum progamm size for MicroControllers (contributed by https://github.com/XZ1048576 ) 29 | --------------------------------------------------------------------------------------------------- 30 | Version: 0.10.10 31 | Date: 19. 02. 2023 32 | Locale: 33 | - Added Ukrainian translation (contributed by @Met_en_Bouldry on crowdin) 34 | --------------------------------------------------------------------------------------------------- 35 | Version: 0.10.9 36 | Date: 24. 08. 2021 37 | Changes: 38 | - Improved icons 39 | --------------------------------------------------------------------------------------------------- 40 | Version: 0.10.8 41 | Date: 20. 08. 2021 42 | Changes: 43 | - Added an info icon 44 | --------------------------------------------------------------------------------------------------- 45 | Version: 0.10.7 46 | Date: 20. 08. 2021 47 | Changes: 48 | - Refactored slightly 49 | - Improved stability slightly 50 | Bugfixes: 51 | - Fixed "bno" 52 | --------------------------------------------------------------------------------------------------- 53 | Version: 0.10.6 54 | Date: 19. 08. 2021 55 | Changes: 56 | - Changed examples in the scenario 57 | - Changed positions of output for: 58 | - [add|mul|bnd|bor|bxr|bls|brs|blr|brr|bno] N memN 59 | --------------------------------------------------------------------------------------------------- 60 | Version: 0.10.5 61 | Date: 19. 08. 2021 62 | Bugfixes: 63 | - Fixed some details in documentations 64 | Changes: 65 | - Reworked the scenario and added many examples in the scenario 66 | Notes: 67 | - I confused SRC with DST! (I'll change it soon, I hope) 68 | --------------------------------------------------------------------------------------------------- 69 | Version: 0.10.4 70 | Date: 19. 08. 2021 71 | Bugfixes: 72 | - Fixed a typo in the game 73 | --------------------------------------------------------------------------------------------------- 74 | Version: 0.10.3 75 | Date: 19. 08. 2021 76 | Bugfixes: 77 | - Fixed some details in documentations 78 | --------------------------------------------------------------------------------------------------- 79 | Version: 0.10.2 80 | Date: 19. 08. 2021 81 | Changes: 82 | - Improved documentation 83 | --------------------------------------------------------------------------------------------------- 84 | Version: 0.10.1 85 | Date: 19. 08. 2021 86 | Changes: 87 | - Improved documentation 88 | --------------------------------------------------------------------------------------------------- 89 | Version: 0.10.0 90 | Date: 19. 08. 2021 91 | Bugfixes: 92 | - Fixed data of old MicroControllers 93 | --------------------------------------------------------------------------------------------------- 94 | Version: 0.9.7 95 | Date: 19. 08. 2021 96 | Bugfixes: 97 | - Fixed data of MicroControllers! 98 | --------------------------------------------------------------------------------------------------- 99 | Version: 0.9.6 100 | Date: 19. 08. 2021 101 | Changes: 102 | - Improved UI 103 | --------------------------------------------------------------------------------------------------- 104 | Version: 0.9.5 105 | Date: 18. 08. 2021 106 | Bugfixes: 107 | - Fixed operations with "memN" etc 108 | --------------------------------------------------------------------------------------------------- 109 | Version: 0.9.4 110 | Date: 18. 08. 2021 111 | Bugfixes: 112 | - Fixed `out` (Factorio API works a bit weirder) 113 | --------------------------------------------------------------------------------------------------- 114 | Version: 0.9.3 115 | Date: 18. 08. 2021 116 | Changes: 117 | - Returned the scenario with examples 118 | --------------------------------------------------------------------------------------------------- 119 | Version: 0.9.2 120 | Date: 10. 07. 2021 121 | Bugfixes: 122 | - Game crushes due to data of a microcontroller when a player trying to remove the microcontroller (hotfix, happens sometimes) 123 | --------------------------------------------------------------------------------------------------- 124 | Version: 0.9.1 125 | Date: 04. 01. 2021 126 | Features: 127 | - Added "Update tick time" setting 128 | Notes: 129 | - Works much faster if "Update tick time" set 60 130 | --------------------------------------------------------------------------------------------------- 131 | Version: 0.9.0 132 | Date: 04. 01. 2021 133 | Changes: 134 | - Optimized gui (it doesn't affect too much on UPS now) 135 | - Fixed 'set' command (https://github.com/ZwerOxotnik/m-microcontroller/issues/12) 136 | - Improved style slightly for embed-wiki 137 | - Removed example scenario temporarily 138 | --------------------------------------------------------------------------------------------------- 139 | Version: 0.7.4 140 | Date: 12. 10. 2020 141 | Changes: 142 | - nikolateslax added a technology to MicroControllers (https://github.com/ZwerOxotnik/m-microcontroller/pull/11) 143 | - Reduced size of this mod by optimizing all images 144 | Notes: 145 | - You need to reasearch the technology to get MicroControllers 146 | --------------------------------------------------------------------------------------------------- 147 | Version: 0.7.3 148 | Date: 29. 09. 2020 149 | Changes: 150 | - Possibly fixed data coping (https://mods.factorio.com/mod/m-microcontroller/discussion/5f70b969cfbf9a4b0e744fbb) 151 | --------------------------------------------------------------------------------------------------- 152 | Version: 0.7.1 153 | Date: 26. 07. 2020 154 | Changes: 155 | - Changed the background color 156 | Notes: 157 | - This update for Factorio 0.18 and updated by ZwerOxotnik 158 | - I need much more tests, fix UI style etc 159 | --------------------------------------------------------------------------------------------------- 160 | Version: 0.7.0 161 | Date: 26. 07. 2020 162 | Changes: 163 | - Changed the background color 164 | Notes: 165 | - This update for Factorio 0.17 and updated by ZwerOxotnik 166 | - I need much more tests, fix UI style etc 167 | --------------------------------------------------------------------------------------------------- 168 | Version: 0.6.3 169 | Date: 25. 07. 2020 170 | Changes: 171 | - Changed the background color 172 | Notes: 173 | - This update for Factorio 0.18 and updated by ZwerOxotnik 174 | - I need much more tests, fix UI style etc 175 | --------------------------------------------------------------------------------------------------- 176 | Version: 0.6.2 177 | Date: 25. 07. 2020 178 | Changes: 179 | - Changed the background color 180 | Notes: 181 | - This update for Factorio 0.17 and updated by ZwerOxotnik 182 | - I need much more tests, fix UI style etc 183 | --------------------------------------------------------------------------------------------------- 184 | Version: 0.6.1 185 | Date: 24. 07. 2020 186 | Features: 187 | - You can copy the code and paste to micro controllers 188 | Notes: 189 | - This update for Factorio 0.18 and updated by ZwerOxotnik 190 | - I need much more tests, fix UI style etc 191 | --------------------------------------------------------------------------------------------------- 192 | Version: 0.6.0 193 | Date: 24. 07. 2020 194 | Features: 195 | - You can copy the code and paste to micro controllers 196 | Notes: 197 | - This update for Factorio 0.17 and updated by ZwerOxotnik 198 | - I need much more tests, fix UI style etc 199 | --------------------------------------------------------------------------------------------------- 200 | Version: 0.5.8 201 | Date: 15. 12. 2019 202 | Features: 203 | - Added compact FAL's wiki 204 | Changes: 205 | - Changed FAL REFERENCE 206 | Notes: 207 | - This update for Factorio 0.17 and updated by ZwerOxotnik 208 | - I need much more tests, fix UI style etc 209 | --------------------------------------------------------------------------------------------------- 210 | Version: 0.5.7 211 | Date: 14. 12. 2019 212 | Features: 213 | - There are examples in scenario "MicroController/examples" now 214 | Changes: 215 | - Added new FAL REFERENCE 216 | - Changed stack size of the controllers 217 | Notes: 218 | - This update for Factorio 0.17 and updated by ZwerOxotnik 219 | - I need much more tests, fix UI style etc 220 | 221 | --------------------------------------------------------------------------------------------------- 222 | Version: 0.5.3 223 | Date: 09. 11. 2019 224 | Bugfixes: 225 | - Fixed a bug related to desynchronization on on_built_entity, on_robot_built_entity events 226 | Changes: 227 | - Changed user interface 228 | - Refactoring 229 | Notes: 230 | - This update for Factorio 0.17 and updated by ZwerOxotnik 231 | - I need much more tests, fix UI style etc 232 | 233 | --------------------------------------------------------------------------------------------------- 234 | Version: 0.5.2 235 | Date: 08. 11. 2019 236 | Changes: 237 | - Added FAL reference in the mod folder 238 | - Updated info 239 | Notes: 240 | - This update for Factorio 0.17 and updated by ZwerOxotnik 241 | - I need much more tests, fix UI style etc 242 | 243 | --------------------------------------------------------------------------------------------------- 244 | Version: 0.5.1 245 | Date: 08. 11. 2019 246 | Bugfixes: 247 | - Fixed UI of input 248 | Notes: 249 | - This update for Factorio 0.17 and updated by ZwerOxotnik 250 | - I need much more tests, fix UI style etc 251 | 252 | --------------------------------------------------------------------------------------------------- 253 | Version: 0.5.0 254 | Date: 06. 11. 2019 255 | Notes: 256 | - This update for Factorio 0.17 and updated by ZwerOxotnik 257 | - I need much more tests etc -------------------------------------------------------------------------------- /constants.lua: -------------------------------------------------------------------------------- 1 | NULL_SIGNAL = {signal = { type = "virtual", name = "signal-black" }, count = 0} 2 | HALT_SIGNAL = {signal = { type = "virtual", name = "signal-mc-halt"} , count = 1} 3 | RUN_SIGNAL = {signal = { type = "virtual", name = "signal-mc-run"}, count = 1} 4 | STEP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-step"}, count = 1} 5 | SLEEP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-sleep"}, count = 1} 6 | JUMP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-jump"}, count = 1} 7 | OP_NOP = {type = 'nop'} 8 | 9 | -- {type = "instruction", name = ""} 10 | -- {type = "description", name = "", with_example = true} 11 | -- with_note = true 12 | 13 | local OLD_HELP_TEXT = [[ 14 | -- Registers (Read/Write): 15 | mem1 mem2 mem3 mem4 out 16 | -- Registers (Read Only): 17 | mem5/ipt : Instruction pointer index 18 | mem6/cnr : Number of signals on the red wire 19 | mem7/cng : Number of signals on the green wire 20 | mem8/clk : Clock (monotonic, always runnning) 21 | -- Modules: 22 | You can connect RAM Modules or other MicroControllers by placing 23 | them above or below this MicroController. 24 | External memory is mapped to: 25 | mem11-14 (North Port 1) 26 | mem21-24 (South Port 1) 27 | mem31-34 (North Port 2) 28 | mem41-44 (South Port 2) 29 | MicroControllers can only connect to North and South port 1. 30 | --- Wires: 31 | red1 red2 redN... 32 | green1 green2 greenN... 33 | --- Pointers: 34 | mem@N : Access memN where X is the value at memN 35 | red@N : Access redX where X is the value at memN 36 | green@N : Access greenX where X is the value at memN 37 | --- Glossary: 38 | Signal : A type and integer value. 39 | Value : The integer value part of a signal. 40 | Move : Copy a signal from one source to another. 41 | Set : Set the Value of a register. 42 | Register : A place that can store a signal. 43 | Clear : Reset a register back to Black 0 (the NULL signal). 44 | Find signal : Looks for a signal that has the same type 45 | as the type stored in a register. 46 | Label : A text identifier used for jumps. 47 | --- Key: 48 | W = Wire, I = Integer 49 | M = Memory, O = Output 50 | R = Register (Memory or Output) 51 | L = Label (:id) 52 | ------- OP CODES --------- 53 | OP A B : DESCRIPTION 54 | ------------:------------- 55 | MOV W/R R...: Move signal from [A] to register(s). 56 | SET M/I R : Set [B] signal count to [A]. 57 | SWP R R : Swap [A] with [B]. 58 | CLR R... : Clear register(s). Clears all if none specified. 59 | FIR R : Find signal R from the red wire and move to mem1. 60 | FIG R : Find signal R from the green wire and move to mem1. 61 | JMP M/I/L : Jump to line [A] or label. 62 | HLT : Halt the program. 63 | NOP : No Operation. 64 | --- Arithmetic Op Codes: 65 | All arithmetic ops ignore type, type in memN is preserved. 66 | ADD M/I M/I : Add [A] + [B], store result in memN. 67 | SUB M/I M/I : Subtract [A] - [B], store result in memN. 68 | MUL M/I M/I : Multiply [A] * [B], store result in memN. 69 | DIV M/I M/I : Divide [A] / [B], store result in memN. 70 | MOD M/I M/I : Modulo [A] % [B], store result in memN. 71 | POW M/I M/I : Raise [A] to power of [B], store result in memN. 72 | DIG M/I : Gets the [A]th digit from mem1, store result in mem1. 73 | DIS M/I M/I : Sets the [A]th digit from mem1 to the 1st digit from [B]. 74 | BND M/I M/I : Bitwise [A] AND [B] 75 | BOR M/I M/I : Bitwise [A] OR [B] 76 | BXR M/I M/I : Bitwise [A] XOR [B] 77 | BNO M/I : Bitwise NOT [A] 78 | BLS M/I M/I : Bitwise LEFT SHIFT [A] by [B] 79 | BRS M/I M/I : Bitwise RIGHT SHIFT [A] by [B] 80 | BLR M/I M/I : Bitwise LEFT ROTATE [A] by [B] 81 | BRR M/I M/I : Bitwise RIGHT ROTATE [A] by [B] 82 | --- Test Op Codes: 83 | Test Ops will skip the next line if the test is successful. 84 | TGT M/I M/I : Tests if [A] value greater than [B] value. 85 | TLT M/I M/I : Tests if [A] value less than [B] value. 86 | TEQ M/I M/I : Tests if [A] value equals [B] value. 87 | TNQ M/I M/I : Tests if [A] value does not equal [B] value. 88 | TTE M M : Tests if [A] type equals [B] type. 89 | TTN M M : Tests if [A] type does not equal [B] type. 90 | --- Blocking Op Codes: 91 | Blocking Ops will pause the program until the operation is complete. 92 | SLP M/I : Sleep for [A] ticks. 93 | BKR M/I : Block until there's [a]+ signals on the red wire. 94 | BKG M/I : Block until there's [a]+ signals on the green wire. 95 | SYN : Blocks until all other connected microcontrollers SYN. 96 | --- Interrupts: 97 | You can send interrupting signals to a microcontroller. 98 | There are: HLT (halt), RUN (run), STP (step), SLP (sleep) and JMP (jump). 99 | If a microcontroller receives any one of these signals it will 100 | execute them immediately. 101 | ------------------------------------------------------------------------- 102 | ------------------------------------------------------------------------- 103 | -- Example 1: 104 | # Outputs the first signal 105 | # from red multiplied by 2. 106 | mov red1 mem1 107 | mul mem1 2 108 | mov mem1 out 109 | jmp 2 110 | -- Example 2: 111 | # accumulates first 4 112 | # signals on the red wire. 113 | :SETUP 114 | clr 115 | set 11 mem2 116 | set 1 mem3 117 | :LOOP 118 | mov red@3 mem1 119 | add mem1 mem@2 120 | mov mem1 mem@2 121 | :NEXT 122 | add mem2 1 123 | tlt mem1 15 124 | set 11 mem1 125 | mov mem1 mem2 126 | add mem3 1 127 | tlt mem1 5 128 | set 1 mem1 129 | mov mem1 mem3 130 | jmp :LOOP 131 | ]] 132 | 133 | local BIS_DESCRIPTION = [[ 134 | <:I> specifies a parameter that takes a literal integer. 135 | <:R> specifies a parameter that takes a register address. 136 | <:W> specifies a parameter that takes a wire Input address. 137 | <:L> specifies a parameter that takes a label. 138 | ]] 139 | 140 | local EXAMPLE1 = ":LOOP\njmp :LOOP" 141 | local EXAMPLE2 = "fig mem21\nmul mem1 2\nmov mem1 out" 142 | local EXAMPLE3 = ":60 second clock.\nadd mem1 1\nmod mem1 60\njmp 1" 143 | local EXAMPLE4 = [[ 144 | mov red1 mem1 145 | mul mem1 2 146 | mov mem1 out 147 | ]] 148 | local EXAMPLE5 = [[ 149 | clr 150 | set 11 mem2 151 | set 3 mem2 152 | :loop 153 | mov red@3 mem1 154 | add mem1 mem@2 155 | mov mem1 mem@2 156 | add mem2 1 157 | tlt mem1 15 158 | set 11 mem1 159 | mov mem1 mem2 160 | add mem3 1 161 | tlt mem1 5 162 | set 1 mem1 163 | mov mem1 mem3 164 | ]] 165 | 166 | DOCS = { 167 | { 168 | name = "overview", 169 | content = { 170 | {name = "registers"}, 171 | {name = "mapped-memory"} 172 | } 173 | }, 174 | { 175 | name = "glossary", 176 | content = { 177 | {name = "signal_glossary"}, 178 | {name = "type_glossary"}, 179 | {name = "value_glossary"}, 180 | {name = "move_glossary"}, 181 | {name = "set_glossary"}, 182 | {name = "register_glossary"}, 183 | {name = "clear_glossary"}, 184 | {name = "null_glossary"}, 185 | {name = "label_glossary"} 186 | } 187 | }, 188 | { 189 | name = "basic_instructions_set", 190 | content = { 191 | {example = BIS_DESCRIPTION}, 192 | {name = "description_BIS"}, 193 | {name = "comments_BIS", syntax = "#"}, 194 | {name = "labels_BIS", syntax = "#