{"id":20660976,"url":"https://github.com/liatemplates/digisim","last_synced_at":"2025-10-11T13:32:25.844Z","repository":{"id":107238728,"uuid":"248762407","full_name":"LiaTemplates/DigiSim","owner":"LiaTemplates","description":"Template for using SimcirJS to simulate circuits in LiaScript","archived":false,"fork":false,"pushed_at":"2020-08-05T18:27:12.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-11T13:32:02.129Z","etag":null,"topics":["circuit","liascript","liascript-template","simulation"],"latest_commit_sha":null,"homepage":"https://liascript.github.io/course/?https://raw.githubusercontent.com/LiaTemplates/DigiSim/master/README.md","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LiaTemplates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-20T13:29:24.000Z","updated_at":"2022-02-22T12:46:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"929e416f-5c65-4214-9ac0-ce8952bd769f","html_url":"https://github.com/LiaTemplates/DigiSim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LiaTemplates/DigiSim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FDigiSim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FDigiSim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FDigiSim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FDigiSim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LiaTemplates","download_url":"https://codeload.github.com/LiaTemplates/DigiSim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LiaTemplates%2FDigiSim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007339,"owners_count":26084282,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circuit","liascript","liascript-template","simulation"],"created_at":"2024-11-16T19:06:40.850Z","updated_at":"2025-10-11T13:32:25.761Z","avatar_url":"https://github.com/LiaTemplates.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nauthor:   Yannik Höll \u0026 André Dietrich\n\nemail:    labruzzler@gmail.com \u0026 andre.dietrich@ovgu.de\n\nversion:  0.0.1\n\nlanguage: en\n\nnarrator: US English Female\n\nscript:   https://cdn.jsdelivr.net/gh/liaTemplates/DigiSim/js/parser.min.js\nscript:   https://tilk.github.io/digitaljs/main.js\n\n@onload\n// create custom html element for the circuit\n\ncustomElements.define('digi-sim', class extends HTMLElement {\n  constructor () {\n    super()\n  }\n  connectedCallback () {\n    this.json = JSON.parse(this.textContent)\n    this.textContent = \"\"\n\n    this.id_ = Math.random().toString(36)\n\n    let div = document.createElement('div')\n    div.id = this.id_\n    div.style = \"width: 100%; height: 400px\"\n    this.appendChild(div)\n\n    this.init()\n  }\n  init() {\n    if(!this.circuit) {\n      try {\n        this.circuit = new digitaljs.Circuit(this.json);\n        let div = document.getElementById(this.id_);\n        this.paper = this.circuit.displayOn(div);\n        this.circuit.start()\n      } catch (e) {\n        alert(e)\n        let self = this\n        setTimeout(function() {self.init()}, 100)\n      }\n    }\n  }\n  disconnectedCallback () {\n    if (super.disconnectedCallback) {\n      super.disconnectedCallback()\n    }\n    this.circuit.stop()\n  }\n});\n\n// predefine some circuits\nButton(\"btn_s\", \"S\", {x: 50, y: 165});\nButton(\"btn_r\", \"R\", {x: 50, y: 45});\n\nNOR([\"r\", \"nor1\"], [\"q\"], \"\", 1, {x: 200, y: 50});\nNOR([\"nor2\", \"s\"], [\"q_\"], \"\", 1, {x: 200, y: 150});\n\nLamp(\"lmp_q\", \"Q\", {x: 350, y: 55});\nLamp(\"lmp_q_\", \"~Q\", {x: 350, y: 155});\n\nwire(\"btn_s\", \"s\");\nwire(\"btn_r\", \"r\");\nwire(\"q\", \"nor2\");\nwire(\"q_\", \"nor1\");\nwire(\"q\", \"lmp_q\");\nwire(\"q_\", \"lmp_q_\");\nfinalizeJSON(\"sr_latch\");\n@end\n\n@DigiSim.runJson: @DigiSim._evalJson(@uid,```@input```)\n\n@DigiSim.evalJson: @DigiSim._evalJson(@uid,```@0```)\n\n@DigiSim._evalJson\n\u003cscript\u003e\n  document.getElementById(\"sim_@0\").innerHTML= `\u003cdigi-sim\u003e@1\u003c/digi-sim\u003e`\n  \"LIA: stop\"\n\u003c/script\u003e\n\n\u003cdiv id=\"sim_@0\"\u003e\u003c/div\u003e\n@end\n\n@DigiSim.insertCircuit: @DigiSim._insertCircuit_(@0, @uid)\n\n@DigiSim._insertCircuit_\n\u003cscript\u003e\n  insertCircuit(`@0`, `sim_insert_@1`);\n  \"LIA: stop\"\n\u003c/script\u003e\n\n\u003cdiv id=\"sim_insert_@1\"\u003eLoading Circuit\u003c/div\u003e\n@end\n\n@DigiSim.eval: @DigiSim._eval_(```@0```, @uid)\n\n@DigiSim._eval_\n\u003cscript\u003e\n  eval(`@0`);\n\n  const rand = Math.random().toString();\n  finalizeJSON(`dev_${rand}`);\n  insertCircuit(`dev_${rand}`, \"sim_eval_@1\");\n  \"LIA: stop\"\n\u003c/script\u003e\n\n\u003cdiv id=\"sim_eval_@1\"\u003e\u003c/div\u003e\n@end\n\ndark: false\n--\u003e\n\n# DigiSim for LiaScript\n\nImplementation of DigitalJs for Liascript\n[DigitalJS Source](https://github.com/tilk/digitaljs)\n\n## `@DigiSim.evalJson`\n\nPut the JSON of your circuit into Markdown ticks and put the makro `@DigiSim.evalJson` at the first line of your markdown and the circuit will be evaluated and shown.\n\n\n``` json @DigiSim.evalJson\n{\n  \"devices\": {\n    \"dev0\": {\n      \"label\": \"s\",\n      \"position\": {\n        \"x\": 0,\n        \"y\": 20\n      },\n      \"celltype\": \"$button\",\n      \"propagation\": 0\n    },\n    \"dev1\": {\n      \"label\": \"r\",\n      \"position\": {\n        \"x\": 155,\n        \"y\": 75\n      },\n      \"celltype\": \"$button\",\n      \"propagation\": 0\n    },\n    \"dev2\": {\n      \"label\": \"q\",\n      \"position\": {\n        \"x\": 480,\n        \"y\": 55\n      },\n      \"celltype\": \"$lamp\",\n      \"propagation\": 1\n    },\n    \"dev3\": {\n      \"label\": \"nq\",\n      \"position\": {\n        \"x\": 325,\n        \"y\": 0\n      },\n      \"celltype\": \"$lamp\",\n      \"propagation\": 1\n    },\n    \"dev6\": {\n      \"label\": \"$or$_input.sv:7$1\",\n      \"position\": {\n        \"x\": 310,\n        \"y\": 50\n      },\n      \"celltype\": \"$nor\",\n      \"propagation\": 1,\n      \"bits\": 1\n    },\n    \"dev7\": {\n      \"label\": \"$or$_input.sv:8$3\",\n      \"position\": {\n        \"x\": 140,\n        \"y\": 15\n      },\n      \"celltype\": \"$nor\",\n      \"propagation\": 1,\n      \"bits\": 1\n    }\n  },\n  \"connectors\": [\n    {\n      \"from\": {\n        \"id\": \"dev0\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev7\",\n        \"port\": \"in1\"\n      },\n      \"name\": \"s\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev1\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev6\",\n        \"port\": \"in1\"\n      },\n      \"name\": \"r\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev6\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev2\",\n        \"port\": \"in\"\n      },\n      \"name\": \"q\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev6\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev7\",\n        \"port\": \"in2\"\n      },\n      \"name\": \"q\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev7\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev3\",\n        \"port\": \"in\"\n      },\n      \"name\": \"nq\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev7\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev6\",\n        \"port\": \"in2\"\n      },\n      \"name\": \"nq\",\n      \"vertices\": []\n    }\n  ],\n  \"subcircuits\": {}\n}\n```\n\nTo get the JSON of a circuit you have to visite the website if\n[Yosys2digitaljs](https://digitaljs.tilk.eu/) and put the\n[Verilog](https://en.wikipedia.org/wiki/Verilog) representation of the circuit\nin the text field on the website. Afterwards you have to click the save button\nnear the timer in the upper right corner and save the JSON on your computer. The\nsimply copy the JSON from the file into the LiaScript Document.\n\nYou can also write the JSON by hand. A document of the JSON format will also be\nincluded in this documentation.\n\n### Multiple Circuits\n\nIt is also possible to put multiple circuits on the same site of your LiaScript\ndocument as shown below.\n\n\n`D-Latch`\n``` json @DigiSim.evalJson\n{\n    \"devices\": {\n        \"dev0\": {\n            \"label\": \"d\",\n            \"position\": {\n                \"x\": 0,\n                \"y\": 32.5\n            },\n            \"celltype\": \"$button\",\n            \"propagation\": 0\n        },\n        \"dev1\": {\n            \"label\": \"e\",\n            \"position\": {\n                \"x\": 0,\n                \"y\": 82.5\n            },\n            \"celltype\": \"$button\",\n            \"propagation\": 0\n        },\n        \"dev2\": {\n            \"label\": \"q\",\n            \"position\": {\n                \"x\": 660,\n                \"y\": 65\n            },\n            \"celltype\": \"$lamp\",\n            \"propagation\": 1\n        },\n        \"dev3\": {\n            \"label\": \"nq\",\n            \"position\": {\n                \"x\": 660,\n                \"y\": 10\n            },\n            \"celltype\": \"$lamp\",\n            \"propagation\": 1\n        },\n        \"dev4\": {\n            \"position\": {\n                \"x\": 275,\n                \"y\": 95\n            },\n            \"celltype\": \"$and\",\n            \"propagation\": 1,\n            \"bits\": 1\n        },\n        \"dev5\": {\n            \"position\": {\n                \"x\": 290,\n                \"y\": -5\n            },\n            \"celltype\": \"$and\",\n            \"propagation\": 1,\n            \"bits\": 1\n        },\n        \"dev7\": {\n            \"position\": {\n                \"x\": 95,\n                \"y\": 105\n            },\n            \"celltype\": \"$not\",\n            \"propagation\": 1,\n            \"bits\": 1\n        },\n        \"dev9\": {\n            \"position\": {\n                \"x\": 450,\n                \"y\": 5\n            },\n            \"celltype\": \"$nor\",\n            \"propagation\": 1,\n            \"bits\": 1\n        },\n        \"dev10\": {\n            \"position\": {\n                \"x\": 440,\n                \"y\": 105\n            },\n            \"celltype\": \"$nor\",\n            \"propagation\": 1,\n            \"bits\": 1\n        }\n    },\n    \"connectors\": [\n        {\n            \"from\": {\n                \"id\": \"dev0\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev5\",\n                \"port\": \"in2\"\n            },\n            \"name\": \"d\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev0\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev7\",\n                \"port\": \"in\"\n            },\n            \"name\": \"d\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev1\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev4\",\n                \"port\": \"in1\"\n            },\n            \"name\": \"e\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev1\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev5\",\n                \"port\": \"in1\"\n            },\n            \"name\": \"e\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev10\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev2\",\n                \"port\": \"in\"\n            },\n            \"name\": \"q\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev10\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev9\",\n                \"port\": \"in2\"\n            },\n            \"name\": \"q\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev9\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in\"\n            },\n            \"name\": \"nq\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev9\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev10\",\n                \"port\": \"in2\"\n            },\n            \"name\": \"nq\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev7\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev4\",\n                \"port\": \"in2\"\n            },\n            \"name\": \"nd\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev4\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev10\",\n                \"port\": \"in1\"\n            },\n            \"name\": \"r\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev5\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev9\",\n                \"port\": \"in1\"\n            },\n            \"name\": \"s\",\n            \"vertices\": []\n        }\n    ],\n    \"subcircuits\": {}\n}\n```\n\n`Priority encoder`\n``` json @DigiSim.evalJson\n{\n    \"devices\": {\n        \"dev0\": {\n            \"label\": \"y\",\n            \"position\": {\n                \"x\": 901.09375,\n                \"y\": 191.5\n            },\n            \"celltype\": \"$numdisplay\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"bits\": 2\n        },\n        \"dev1\": {\n            \"label\": \"valid\",\n            \"position\": {\n                \"x\": 903.109375,\n                \"y\": 241.5\n            },\n            \"celltype\": \"$lamp\",\n            \"propagation\": 1\n        },\n        \"dev2\": {\n            \"label\": \"a\",\n            \"position\": {\n                \"x\": 0,\n                \"y\": 120.5\n            },\n            \"celltype\": \"$numentry\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"bits\": 4\n        },\n        \"dev3\": {\n            \"label\": \"$procmux$3\",\n            \"position\": {\n                \"x\": 603.609375,\n                \"y\": 187.5\n            },\n            \"celltype\": \"$pmux\",\n            \"propagation\": 1,\n            \"bits\": {\n                \"in\": 3,\n                \"sel\": 4\n            }\n        },\n        \"dev4\": {\n            \"label\": \"$procmux$4_CMP0\",\n            \"position\": {\n                \"x\": 303.5625,\n                \"y\": 0\n            },\n            \"celltype\": \"$eq\",\n            \"propagation\": 1,\n            \"bits\": {\n                \"in1\": 4,\n                \"in2\": 1\n            },\n            \"signed\": {\n                \"in1\": false,\n                \"in2\": false\n            }\n        },\n        \"dev5\": {\n            \"label\": \"$procmux$5_CMP0\",\n            \"position\": {\n                \"x\": 303.5625,\n                \"y\": 60\n            },\n            \"celltype\": \"$eq\",\n            \"propagation\": 1,\n            \"bits\": {\n                \"in1\": 3,\n                \"in2\": 1\n            },\n            \"signed\": {\n                \"in1\": false,\n                \"in2\": false\n            }\n        },\n        \"dev6\": {\n            \"label\": \"$procmux$6_CMP0\",\n            \"position\": {\n                \"x\": 303.5625,\n                \"y\": 145.5\n            },\n            \"celltype\": \"$eq\",\n            \"propagation\": 1,\n            \"bits\": {\n                \"in1\": 2,\n                \"in2\": 1\n            },\n            \"signed\": {\n                \"in1\": false,\n                \"in2\": false\n            }\n        },\n        \"dev7\": {\n            \"position\": {\n                \"x\": 459.5859375,\n                \"y\": 99.5\n            },\n            \"celltype\": \"$busgroup\",\n            \"propagation\": 0,\n            \"groups\": [\n                1,\n                1,\n                1,\n                1\n            ]\n        },\n        \"dev8\": {\n            \"position\": {\n                \"x\": 453.5625,\n                \"y\": 49.5\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"000\"\n        },\n        \"dev9\": {\n            \"position\": {\n                \"x\": 453.5625,\n                \"y\": 191.5\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"111\"\n        },\n        \"dev10\": {\n            \"position\": {\n                \"x\": 453.5625,\n                \"y\": 241.5\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"101\"\n        },\n        \"dev11\": {\n            \"position\": {\n                \"x\": 453.5625,\n                \"y\": 291.5\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"011\"\n        },\n        \"dev12\": {\n            \"position\": {\n                \"x\": 453.5625,\n                \"y\": 341.5\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"001\"\n        },\n        \"dev13\": {\n            \"position\": {\n                \"x\": 160.8125,\n                \"y\": 65\n            },\n            \"celltype\": \"$constant\",\n            \"propagation\": 0,\n            \"numbase\": \"hex\",\n            \"constant\": \"1\"\n        },\n        \"dev14\": {\n            \"position\": {\n                \"x\": 753.609375,\n                \"y\": 194.5\n            },\n            \"celltype\": \"$busslice\",\n            \"propagation\": 0,\n            \"slice\": {\n                \"first\": 1,\n                \"count\": 2,\n                \"total\": 3\n            }\n        },\n        \"dev15\": {\n            \"position\": {\n                \"x\": 758.34375,\n                \"y\": 244.5\n            },\n            \"celltype\": \"$busslice\",\n            \"propagation\": 0,\n            \"slice\": {\n                \"first\": 0,\n                \"count\": 1,\n                \"total\": 3\n            }\n        },\n        \"dev16\": {\n            \"position\": {\n                \"x\": 156.078125,\n                \"y\": 119.5\n            },\n            \"celltype\": \"$busslice\",\n            \"propagation\": 0,\n            \"slice\": {\n                \"first\": 1,\n                \"count\": 3,\n                \"total\": 4\n            }\n        },\n        \"dev17\": {\n            \"position\": {\n                \"x\": 156.078125,\n                \"y\": 163.5\n            },\n            \"celltype\": \"$busslice\",\n            \"propagation\": 0,\n            \"slice\": {\n                \"first\": 2,\n                \"count\": 2,\n                \"total\": 4\n            }\n        },\n        \"dev18\": {\n            \"position\": {\n                \"x\": 309.5546875,\n                \"y\": 205.5\n            },\n            \"celltype\": \"$busslice\",\n            \"propagation\": 0,\n            \"slice\": {\n                \"first\": 3,\n                \"count\": 1,\n                \"total\": 4\n            }\n        }\n    },\n    \"connectors\": [\n        {\n            \"from\": {\n                \"id\": \"dev14\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev0\",\n                \"port\": \"in\"\n            },\n            \"name\": \"y\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev15\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev1\",\n                \"port\": \"in\"\n            },\n            \"name\": \"valid\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev2\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev4\",\n                \"port\": \"in1\"\n            },\n            \"name\": \"a\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev2\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev16\",\n                \"port\": \"in\"\n            },\n            \"name\": \"a\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev2\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev17\",\n                \"port\": \"in\"\n            },\n            \"name\": \"a\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev2\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev18\",\n                \"port\": \"in\"\n            },\n            \"name\": \"a\",\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev8\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in0\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev7\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"sel\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev3\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev14\",\n                \"port\": \"in\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev3\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev15\",\n                \"port\": \"in\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev9\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in1\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev10\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in2\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev11\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in3\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev12\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev3\",\n                \"port\": \"in4\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev13\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev4\",\n                \"port\": \"in2\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev13\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev5\",\n                \"port\": \"in2\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev13\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev6\",\n                \"port\": \"in2\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev4\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev7\",\n                \"port\": \"in3\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev16\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev5\",\n                \"port\": \"in1\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev5\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev7\",\n                \"port\": \"in2\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev17\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev6\",\n                \"port\": \"in1\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev6\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev7\",\n                \"port\": \"in1\"\n            },\n            \"vertices\": []\n        },\n        {\n            \"from\": {\n                \"id\": \"dev18\",\n                \"port\": \"out\"\n            },\n            \"to\": {\n                \"id\": \"dev7\",\n                \"port\": \"in0\"\n            },\n            \"vertices\": []\n        }\n    ],\n    \"subcircuits\": {}\n}\n```\n\n## `@DigiSim.runJson`\n\n``` json\n{\n  \"devices\": {\n    \"dev0\": {\n      \"label\": \"s\",\n      \"position\": {\n        \"x\": 0,\n        \"y\": 20\n      },\n      \"celltype\": \"$button\",\n      \"propagation\": 0\n    },\n    \"dev1\": {\n      \"label\": \"r\",\n      \"position\": {\n        \"x\": 155,\n        \"y\": 75\n      },\n      \"celltype\": \"$button\",\n      \"propagation\": 0\n    },\n    \"dev2\": {\n      \"label\": \"q\",\n      \"position\": {\n        \"x\": 480,\n        \"y\": 55\n      },\n      \"celltype\": \"$lamp\",\n      \"propagation\": 1\n    },\n    \"dev3\": {\n      \"label\": \"nq\",\n      \"position\": {\n        \"x\": 325,\n        \"y\": 0\n      },\n      \"celltype\": \"$lamp\",\n      \"propagation\": 1\n    },\n    \"dev6\": {\n      \"label\": \"$or$_input.sv:7$1\",\n      \"position\": {\n        \"x\": 310,\n        \"y\": 50\n      },\n      \"celltype\": \"$nor\",\n      \"propagation\": 1,\n      \"bits\": 1\n    },\n    \"dev7\": {\n      \"label\": \"$or$_input.sv:8$3\",\n      \"position\": {\n        \"x\": 140,\n        \"y\": 15\n      },\n      \"celltype\": \"$nor\",\n      \"propagation\": 1,\n      \"bits\": 1\n    }\n  },\n  \"connectors\": [\n    {\n      \"from\": {\n        \"id\": \"dev0\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev7\",\n        \"port\": \"in1\"\n      },\n      \"name\": \"s\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev1\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev6\",\n        \"port\": \"in1\"\n      },\n      \"name\": \"r\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev6\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev2\",\n        \"port\": \"in\"\n      },\n      \"name\": \"q\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev6\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev7\",\n        \"port\": \"in2\"\n      },\n      \"name\": \"q\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev7\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev3\",\n        \"port\": \"in\"\n      },\n      \"name\": \"nq\",\n      \"vertices\": []\n    },\n    {\n      \"from\": {\n        \"id\": \"dev7\",\n        \"port\": \"out\"\n      },\n      \"to\": {\n        \"id\": \"dev6\",\n        \"port\": \"in2\"\n      },\n      \"name\": \"nq\",\n      \"vertices\": []\n    }\n  ],\n  \"subcircuits\": {}\n}\n```\n@DigiSim.runJson\n\n## `@DigiSim.insertCircuit(name)`\n\nUsing the `@onload`-macro you cant predefine circuits which can later be inserted into the document with the `@DigiSim.insertCircuit(name)` macro by giving the name of the circuit.\n\n@DigiSim.insertCircuit(sr_latch)\n\n## `@DigiSim.eval`\n\nYou can also use a pseudo RTL code to define your circuit as demostrated below.\n\n\u003cp style=\"color: red\"\u003e__Don't__ use the `finalizeJSON(name)` function in the code, or your circuit will not be shown!\u003c/p\u003e\n\n``` js\n// Init components\nAND([\"and1\", \"and2\"], [\"and3\"], \"AND1\");\nOR([\"or1\", \"or2\"], [\"or3\"], \"OR1\");\nXOR([\"xor1\", \"xor2\"], [\"xor3\"], \"XOR1\");\nButton(\"btn1\", \"BUTTON1\");\nButton(\"btn2\", \"BUTTON2\");\nButton(\"btn3\", \"BUTTON3\");\nButton(\"btn4\", \"BUTTON4\");\nLamp(\"lmp1\", \"LAMP1\");\n\n// IO IN\nwire(\"btn1\", \"and1\");\nwire(\"btn2\", \"and2\");\nwire(\"btn3\", \"or1\");\nwire(\"btn4\", \"or2\");\n\n// AND, OR -\u003e XOR\nwire(\"and3\", \"xor1\");\nwire(\"or3\", \"xor2\");\n\n// IO OUT\nwire(\"xor3\", \"lmp1\", \"Main Output\");\n```\n\n``` js @DigiSim.eval\n// Init components\nAND([\"and1\", \"and2\"], [\"and3\"], \"AND1\");\nOR([\"or1\", \"or2\"], [\"or3\"], \"OR1\");\nXOR([\"xor1\", \"xor2\"], [\"xor3\"], \"XOR1\");\nButton(\"btn1\", \"BUTTON1\");\nButton(\"btn2\", \"BUTTON2\");\nButton(\"btn3\", \"BUTTON3\");\nButton(\"btn4\", \"BUTTON4\");\nLamp(\"lmp1\", \"LAMP1\");\n\n// IO IN\nwire(\"btn1\", \"and1\");\nwire(\"btn2\", \"and2\");\nwire(\"btn3\", \"or1\");\nwire(\"btn4\", \"or2\");\n\n// AND, OR -\u003e XOR\nwire(\"and3\", \"xor1\");\nwire(\"or3\", \"xor2\");\n\n// IO OUT\nwire(\"xor3\", \"lmp1\", \"Main Output\");\n```\n\n# Js Docs\nTo create a circuit you have to call some functions to create components for your circuit and then you can connect them with the `wire(outpurname, inputname, label)` function.\nTo save your circuit you must call the `finalizeJSON(name)` function, which saves a json representation of your circuit and resests the global state so that you can create the next circuit.\n\nExample:\n\n``` js\n@onload\nButton(\"btn1\", \"\");\nButton(\"btn2\", \"\");\nButton(\"btn3\", \"\");\nButton(\"btn4\", \"\");\n\nAND([\"and1\", \"and2\"], [\"and3\"], \"AND1\");\nOR([\"or1\", \"or2\"], [\"or3\"], \"OR1\");\nXOR([\"xor1\", \"xor2\"], [\"xor3\"], \"XOR1\");\n\nLamp(\"lmp1\", \"Main Output\");\n\nwire(\"btn1\", \"and1\", \"\");\nwire(\"btn2\", \"and2\", \"\");\nwire(\"btn3\", \"or1\", \"\");\nwire(\"btn4\", \"or2\", \"\");\n\nwire(\"and3\", \"xor1\", \"\");\nwire(\"or3\", \"xor2\", \"\");\n\nwire(\"xor3\", \"lmp1\", \"\");\nfinalizeJSON(\"ex1\");\n@end\n```\n\nIf you use the `@DigiSim.eval`-macro you \u003cb style=\"color: #ff0000\"\u003edont\u003c/b\u003e have to use the `finalizeJSON(name)` to save your circuit! If you use it in the code it will not display your circuit!\n\n## Simple Logic Gates\n\nYou can simply use this functions to create logic gates in your circuits.\n\n\u003cp\u003e`inputs`:   Array of strings with the name of your inputs.        `type: [String]`\u003c/p\u003e\n\u003cp\u003e`outputs`:  Array of strings with the name of your outputs.       `type: [String]`\u003c/p\u003e\n\u003cp\u003e`label`:    Name that will be displayed next to the component.    `type: String`\u003c/p\u003e\n\u003cp\u003e`bits`:     Size of your data bus in bits.                        `type: Int`\u003c/p\u003e\n\u003cp\u003e`pos`:      Position of the circuit.                              `type: {x: Int, y: Int}`\u003c/p\u003e\n\nAll of these parameters are the same for the upcoming functions.\n\u003cp style=\"color: red\"\u003eIf the parameter is called `input` instead of `inputs` it is not an array of strings but a single string. The same apllies to `output` and `outputs`.\u003c/p\u003e\n\n``` js\nAND(inputs, outputs, label, bits=1, pos=undefined);\nNAND(inputs, outputs, label, bits=1, pos=undefined);\nOR(inputs, outputs, label, bits=1, pos=undefined);\nNOR(inputs, outputs, label, bits=1, pos=undefined);\nXOR(inputs, outputs, label, bits=1, pos=undefined);\nXNOR(inputs, outputs, label, bits=1, pos=undefined);\nNOT(inputs, outputs, label, bits=1, pos=undefined);\n```\n\n## Reducing Gates\n\nThese gates take a bus of the given bit size and reduce its size to 1 bit.\n\n``` js\nReducingAND(input, output, label, bits, pos=undefined)\nReducingNAND(input, output, label, bits, pos=undefined)\nReducingOR(input, output, label, bits, pos=undefined)\nReducingNOR(input, output, label, bits, pos=undefined)\nReducingXOR(input, output, label, bits, pos=undefined)\nReducingXNOR(input, output, label, bits, pos=undefined) // does currently not work properly and produces a reducing xor gate\n```\n\n## IO\n\nComponents that can handle input/output operations.\n\n\u003cp\u003e`bitsIn/bitsOut`:  Determines the bus size only of the input/output of the component.       `type: Int`\u003c/p\u003e\n\u003cp\u003e`base`:  Base of the number system the should be used       `possible values: \"hex\", \"bin\", \"oct\"`\u003c/p\u003e\n\u003cp\u003e`value`: Numeric value that is constantly output by the component. `type: Int`\u003c/p\u003e\n\n``` js\nButton(output, label, pos=undefined)\nLamp(input, label, pos=undefined)\nNumberInput(output, label, bitsOut, base, pos=undefined)\nNumberOutput(input, label, bitsIn, base, pos=undefined)\nNumberConstant(output, label, value, pos=undefined)\n```\n\n## Unary Operations\n\nUnary operations that can be performed on numbers.\n\n\u003cp\u003e`signed`: Determines wheter the numbers are signed or unsigned. `type: Boolean`\u003c/p\u003e\n\n```js\nNegator(input, output, label, bitsIn, bitsOut, signed, pos=undefined)\n```\n\n## Binary Operations\n\nBinary operations that can be performed on numbers.\n\n``` js\nAdd(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nSubtract(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nMultiply(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nDivide(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nModulo(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nPow(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\n```\n\n## Comparison Operations\n\nComparison operations that can be performed on numbers.\n\n``` js\nEquals(inputs, output, label, bitsIn, signed, pos=undefined)\nNotEquals(inputs, output, label, bitsIn, signed, pos=undefined)\nLessThan(inputs, output, label, bitsIn, signed, pos=undefined)\nLessThanOrEqual(inputs, output, label, bitsIn, signed, pos=undefined)\nGreaterThan(inputs, output, label, bitsIn, signed, pos=undefined)\nGreaterThanOrEqual(inputs, output, label, bitsIn, signed, pos=undefined)\n```\n\n## Shift Operations\n\nShift operations that can be performed on numbers.\n\n``` js\nShiftLeft(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\nShiftRight(inputs, output, label, bitsIn, bitsOut, signed, pos=undefined)\n```\n\n## Multiplexer\n\n\n\u003cp\u003e`bitsSel`: Determines the bus size of the select input. `type: Int` \u003c/p\u003e\n\n`Number of inputs: 2 ^ bitSel`\n\n``` js\nMultiplexer(inputs, selInput, output, label, bitsIn, bitsSel, pos=undefined)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Fdigisim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliatemplates%2Fdigisim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliatemplates%2Fdigisim/lists"}