{"id":29801422,"url":"https://github.com/galihru/logicsim","last_synced_at":"2025-10-11T12:32:16.615Z","repository":{"id":306604946,"uuid":"1026710046","full_name":"galihru/logicsim","owner":"galihru","description":"The Logic Simulator is an advanced tool designed to facilitate the understanding of sequential circuit design. This application implements fundamental concepts of computer architecture and digital systems engineering through an intuitive drag-and-drop interface, providin","archived":false,"fork":false,"pushed_at":"2025-08-05T01:33:34.000Z","size":433,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-29T09:02:27.003Z","etag":null,"topics":["logic-gates","logic-simulator","pwa-apps","verilog-hdl","verilog-project","verilog-simulator"],"latest_commit_sha":null,"homepage":"https://galihru.github.io/logicsim/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/galihru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-07-26T12:57:48.000Z","updated_at":"2025-08-05T01:33:38.000Z","dependencies_parsed_at":"2025-07-26T19:36:35.387Z","dependency_job_id":"51cd8a91-3ccd-4bcd-9113-1f3a5f44d2c3","html_url":"https://github.com/galihru/logicsim","commit_stats":null,"previous_names":["galihru/logicsim"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/galihru/logicsim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galihru%2Flogicsim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galihru%2Flogicsim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galihru%2Flogicsim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galihru%2Flogicsim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/galihru","download_url":"https://codeload.github.com/galihru/logicsim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/galihru%2Flogicsim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007167,"owners_count":26084247,"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":["logic-gates","logic-simulator","pwa-apps","verilog-hdl","verilog-project","verilog-simulator"],"created_at":"2025-07-28T09:45:48.105Z","updated_at":"2025-10-11T12:32:16.608Z","avatar_url":"https://github.com/galihru.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Digital Logic Simulator\r\n\r\nA modern, interactive web-based digital logic circuit simulator with comprehensive educational features, real-time simulation capabilities, and advanced visualization tools. Built as a Progressive Web Application (PWA) for seamless cross-platform experience.\r\n\r\n![Gambar](https://github.com/galihru/logicsim/blob/main/ss/Screenshot%202025-08-05%20082444.png)\r\n\r\n## 🎯 Abstract\r\n\r\nThe Digital Logic Simulator is an advanced educational tool designed to facilitate the understanding of Boolean algebra, digital logic circuits, and combinational/sequential circuit design. This application implements fundamental concepts of computer architecture and digital systems engineering through an intuitive drag-and-drop interface, providing real-time circuit simulation, truth table generation, and Verilog HDL code synthesis.\r\n\r\n## 📚 Table of Contents\r\n\r\n- [Features](#-features)\r\n- [Mathematical Foundation](#-mathematical-foundation)\r\n- [Boolean Logic Theory](#-boolean-logic-theory)\r\n- [Circuit Analysis](#-circuit-analysis)\r\n- [System Architecture](#-system-architecture)\r\n- [Installation](#-installation)\r\n- [Usage Guide](#-usage-guide)\r\n- [API Documentation](#-api-documentation)\r\n- [Educational Applications](#-educational-applications)\r\n- [Contributing](#-contributing)\r\n- [Technical Specifications](#-technical-specifications)\r\n- [License](#-license)\r\n\r\n## ✨ Features\r\n\r\n### Core Functionality\r\n\r\n- **Interactive Circuit Design**: Drag-and-drop interface for creating digital logic circuits\r\n- **Real-time Simulation**: Dynamic signal propagation with animated visualization\r\n- **Truth Table Generation**: Automatic generation of comprehensive truth tables with pagination\r\n- **Verilog Code Synthesis**: HDL code generation from visual circuit designs\r\n- **PWA Support**: Offline functionality with service worker caching\r\n- **Responsive Design**: Cross-platform compatibility with adaptive UI\r\n\r\n### Logic Gates Implementation\r\n\r\n- **Basic Gates**: AND, OR, NOT, NAND, NOR, XOR, XNOR\r\n- **I/O Components**: INPUT switches, OUTPUT indicators\r\n- **Advanced Features**: Multi-input gates, configurable delay propagation\r\n- **Visual Feedback**: Color-coded signal states and animation effects\r\n\r\n### Educational Tools\r\n\r\n- **Smart Auto-Arrangement**: Automatic circuit topology optimization\r\n- **Export Capabilities**: JSON circuit files and Verilog HDL export\r\n- **Theme System**: Light/dark mode with accessibility compliance\r\n- **Interactive Tour**: Guided tutorials for new users\r\n\r\n## 🔬 Mathematical Foundation\r\n\r\n### Boolean Algebra Fundamentals\r\n\r\nDigital logic circuits are based on Boolean algebra, a mathematical structure that deals with binary variables and logical operations. The fundamental postulates are:\r\n\r\n#### Basic Laws and Theorems\r\n\r\n**Identity Laws:**\r\n\r\n- A + 0 = A\r\n- A · 1 = A\r\n\r\n**Null Laws:**\r\n\r\n- A + 1 = 1\r\n- A · 0 = 0\r\n\r\n**Idempotent Laws:**\r\n\r\n- A + A = A\r\n- A · A = A\r\n\r\n**Complement Laws:**\r\n\r\n- A + Ā = 1\r\n- A · Ā = 0\r\n\r\n**De Morgan's Theorems:**\r\n\r\n- (A + B)' = A' · B'\r\n- (A · B)' = A' + B'\r\n\r\n#### Mathematical Representation\r\n\r\nFor an n-input Boolean function f(x₁, x₂, ..., xₙ), the function can be expressed in:\r\n\r\n**Sum of Products (SOP) Form:**\r\n\r\n```\r\nf(x₁, x₂, ..., xₙ) = Σᵢ mᵢ = Σᵢ (product terms)\r\n```\r\n\r\n**Product of Sums (POS) Form:**\r\n\r\n```\r\nf(x₁, x₂, ..., xₙ) = Πᵢ Mᵢ = Πᵢ (sum terms)\r\n```\r\n\r\nWhere mᵢ represents minterms and Mᵢ represents maxterms.\r\n\r\n### Logic Gate Truth Tables\r\n\r\n#### Basic Gate Operations\r\n\r\n| A | B | AND | OR | NAND | NOR | XOR | XNOR |\r\n|---|---|-----|----|----- |----- |-----|------|\r\n| 0 | 0 |  0  | 0  |  1   |  1   |  0  |  1   |\r\n| 0 | 1 |  0  | 1  |  1   |  0   |  1  |  0   |\r\n| 1 | 0 |  0  | 1  |  1   |  0   |  1  |  0   |\r\n| 1 | 1 |  1  | 1  |  0   |  0   |  0  |  1   |\r\n\r\n#### Mathematical Functions\r\n\r\n**AND Gate:**\r\n\r\n```\r\nY = A · B = AB\r\n```\r\n\r\n**OR Gate:**\r\n\r\n```\r\nY = A + B\r\n```\r\n\r\n**NOT Gate:**\r\n\r\n```\r\nY = Ā = A'\r\n```\r\n\r\n**NAND Gate:**\r\n\r\n```\r\nY = (A · B)' = (AB)'\r\n```\r\n\r\n**NOR Gate:**\r\n\r\n```\r\nY = (A + B)'\r\n```\r\n\r\n**XOR Gate:**\r\n\r\n```\r\nY = A ⊕ B = A'B + AB'\r\n```\r\n\r\n**XNOR Gate:**\r\n\r\n```\r\nY = (A ⊕ B)' = A'B' + AB\r\n```\r\n\r\n## 🧮 Boolean Logic Theory\r\n\r\n### Canonical Forms\r\n\r\n#### Minterm Expansion\r\n\r\nFor a Boolean function of n variables, there are 2ⁿ possible minterms. Each minterm is a product term where each variable appears exactly once (either complemented or uncomplemented).\r\n\r\n**Minterm Formula:**\r\n\r\n```\r\nmᵢ = x₁^(a₁) · x₂^(a₂) · ... · xₙ^(aₙ)\r\n```\r\n\r\nWhere aᵢ ∈ {0, 1} and x^0 = x', x^1 = x\r\n\r\n#### Maxterm Expansion\r\n\r\nSimilarly, maxterms are sum terms where each variable appears exactly once.\r\n\r\n**Maxterm Formula:**\r\n\r\n```\r\nMᵢ = x₁^(b₁) + x₂^(b₂) + ... + xₙ^(bₙ)\r\n```\r\n\r\nWhere bᵢ ∈ {0, 1} and x^0 = x, x^1 = x'\r\n\r\n### Karnaugh Map Simplification\r\n\r\nFor Boolean function minimization, the simulator implements Karnaugh map logic for optimal circuit reduction:\r\n\r\n**K-map Adjacency Rule:**\r\nTwo cells are adjacent if they differ in exactly one variable position.\r\n\r\n**Grouping Rules:**\r\n\r\n- Groups must contain 2ⁿ cells (1, 2, 4, 8, 16, ...)\r\n- Groups should be as large as possible\r\n- Each group eliminates one variable from the resulting term\r\n\r\n### Functional Completeness\r\n\r\nThe simulator supports functionally complete gate sets:\r\n\r\n- **{NAND}**: Universal gate set\r\n- **{NOR}**: Universal gate set\r\n- **{AND, OR, NOT}**: Standard complete set\r\n\r\n**Proof of NAND Universality:**\r\n\r\n```\r\nNOT A = A NAND A\r\nA AND B = (A NAND B) NAND (A NAND B)\r\nA OR B = (A NAND A) NAND (B NAND B)\r\n```\r\n\r\n## 📊 Circuit Analysis\r\n\r\n### Propagation Delay Analysis\r\n\r\nThe simulator models realistic gate delays using discrete event simulation:\r\n\r\n**Delay Calculation:**\r\n\r\n```\r\ntpd = tpd_gate + tpd_interconnect\r\n```\r\n\r\nWhere:\r\n\r\n- tpd_gate: Intrinsic gate delay\r\n- tpd_interconnect: Wire routing delay\r\n\r\n### Critical Path Analysis\r\n\r\nFor combinational circuits, the critical path determines maximum operating frequency:\r\n\r\n**Critical Path Delay:**\r\n\r\n```\r\nTcritical = max(Σ tpd_gates_in_path)\r\n```\r\n\r\n**Maximum Frequency:**\r\n\r\n```\r\nfmax = 1 / (Tcritical + tsetup + thold)\r\n```\r\n\r\n### Signal Integrity\r\n\r\nThe simulator considers:\r\n\r\n- **Rise/Fall Times**: Signal transition characteristics\r\n- **Noise Margins**: VIH, VIL, VOH, VOL specifications\r\n- **Fan-out Loading**: Current driving capability analysis\r\n\r\n### Circuit Complexity Metrics\r\n\r\n**Gate Count Complexity:**\r\n\r\n```\r\nComplexity = Σ (Gate_Inputs × Gate_Weight)\r\n```\r\n\r\n**Logic Depth:**\r\n\r\n```\r\nDepth = max(levels_from_input_to_output)\r\n```\r\n\r\n## 🏗️ System Architecture\r\n\r\n### Frontend Architecture\r\n\r\n```\r\n┌─────────────────────────────────────┐\r\n│           User Interface            │\r\n├─────────────────────────────────────┤\r\n│     Drag \u0026 Drop Engine              │\r\n├─────────────────────────────────────┤\r\n│     Circuit Simulation Engine       │\r\n├─────────────────────────────────────┤\r\n│     Boolean Logic Processor         │\r\n├─────────────────────────────────────┤\r\n│     Canvas Rendering System         │\r\n└─────────────────────────────────────┘\r\n```\r\n\r\n### Class Hierarchy\r\n\r\n```javascript\r\nDigitalLogicSimulator\r\n├── Gate Management\r\n│   ├── createGate()\r\n│   ├── deleteGate()\r\n│   └── calculateGateOutput()\r\n├── Wire Management\r\n│   ├── createWire()\r\n│   ├── updateWires()\r\n│   └── deleteWire()\r\n├── Simulation Engine\r\n│   ├── simulate()\r\n│   ├── animatedPropagation()\r\n│   └── calculateGateLevels()\r\n└── Export Systems\r\n    ├── generateVerilog()\r\n    ├── generateTruthTable()\r\n    └── saveDesign()\r\n```\r\n\r\n### Data Structures\r\n\r\n**Gate Object Structure:**\r\n\r\n```javascript\r\n{\r\n    id: String,           // Unique identifier\r\n    type: String,         // Gate type (AND, OR, NOT, etc.)\r\n    x: Number,           // X coordinate\r\n    y: Number,           // Y coordinate\r\n    inputCount: Number,  // Number of inputs\r\n    inputValues: Array,  // Current input states\r\n    outputValues: Array, // Current output states\r\n    element: HTMLElement // DOM reference\r\n}\r\n```\r\n\r\n**Wire Object Structure:**\r\n\r\n```javascript\r\n{\r\n    id: String,              // Unique identifier\r\n    sourceGate: String,      // Source gate ID\r\n    targetGate: String,      // Target gate ID\r\n    sourcePinIndex: Number,  // Source pin index\r\n    targetPinIndex: Number,  // Target pin index\r\n    element: SVGElement      // SVG path element\r\n}\r\n```\r\n\r\n### Progressive Web App Implementation\r\n\r\n**Service Worker Features:**\r\n\r\n- **Caching Strategy**: Cache-first with network fallback\r\n- **Offline Support**: Full functionality without internet\r\n- **Background Sync**: Circuit data synchronization\r\n- **Push Notifications**: Educational reminders (future feature)\r\n\r\n**Manifest Configuration:**\r\n\r\n```json\r\n{\r\n    \"name\": \"Digital Logic Simulator\",\r\n    \"short_name\": \"Logic Sim\",\r\n    \"start_url\": \"./\",\r\n    \"display\": \"standalone\",\r\n    \"theme_color\": \"#667eea\",\r\n    \"background_color\": \"#f8fafc\"\r\n}\r\n```\r\n\r\n## 🚀 Installation\r\n\r\n### Prerequisites\r\n\r\n- Modern web browser with ES6+ support\r\n- HTTP server for local development\r\n- Python 3.x (for local server) or Node.js\r\n\r\n### Quick Start\r\n\r\n```bash\r\n# Clone the repository\r\ngit clone https://github.com/galihru/logicsim.git\r\n\r\n# Navigate to the project directory\r\ncd digital-logic-simulator\r\n\r\n# Start local server (Python)\r\npython -m http.server 8000\r\n\r\n# Alternative: Start local server (Node.js)\r\nnpx http-server -p 8000\r\n\r\n# Open browser and navigate to\r\n# http://localhost:8000\r\n```\r\n\r\n### Docker Deployment\r\n\r\n```dockerfile\r\nFROM nginx:alpine\r\nCOPY . /usr/share/nginx/html\r\nEXPOSE 80\r\nCMD [\"nginx\", \"-g\", \"daemon off;\"]\r\n```\r\n\r\n```bash\r\n# Build Docker image\r\ndocker build -t digital-logic-simulator .\r\n\r\n# Run container\r\ndocker run -p 8080:80 digital-logic-simulator\r\n```\r\n\r\n## 📖 Usage Guide\r\n\r\n### Basic Circuit Creation\r\n\r\n1. **Add Input Gates**: Drag INPUT components to canvas\r\n2. **Add Logic Gates**: Select desired gate type and drop on canvas\r\n3. **Add Output Gates**: Place OUTPUT components\r\n4. **Connect Gates**: Click source pin, then target pin\r\n5. **Simulate**: Click \"Simulate\" button to run analysis\r\n\r\n### Advanced Features\r\n\r\n#### Truth Table Generation\r\n\r\nThe simulator automatically generates truth tables for circuits with up to 8 inputs (256 rows). For larger circuits, pagination is implemented:\r\n\r\n```javascript\r\n// Truth table generation algorithm\r\nfunction generateTruthTable(inputGates, outputGates) {\r\n    const numInputs = inputGates.length;\r\n    const numCombinations = Math.pow(2, numInputs);\r\n    \r\n    for (let i = 0; i \u003c numCombinations; i++) {\r\n        // Convert i to binary representation\r\n        const binaryString = i.toString(2).padStart(numInputs, '0');\r\n        \r\n        // Set input values and simulate\r\n        setInputValues(binaryString);\r\n        propagateSignals();\r\n        \r\n        // Record output values\r\n        recordOutputs(i);\r\n    }\r\n}\r\n```\r\n\r\n#### Verilog Code Generation\r\n\r\nThe simulator generates synthesizable Verilog HDL code:\r\n\r\n```verilog\r\nmodule digital_circuit(\r\n    input wire [n-1:0] inputs,\r\n    output wire [m-1:0] outputs\r\n);\r\n    // Gate instantiations\r\n    // Wire declarations\r\n    // Logic assignments\r\nendmodule\r\n```\r\n\r\n### Keyboard Shortcuts\r\n\r\n| Shortcut | Action |\r\n|----------|--------|\r\n| `Escape` | Cancel connection mode |\r\n| `Delete` | Delete selected gate |\r\n| `Ctrl+S` | Save circuit |\r\n| `Ctrl+O` | Load circuit |\r\n| `Ctrl+R` | Run simulation |\r\n\r\n## 📚 API Documentation\r\n\r\n### Core Methods\r\n\r\n#### `createGate(type, x, y)`\r\n\r\nCreates a new logic gate at specified coordinates.\r\n\r\n**Parameters:**\r\n\r\n- `type` (String): Gate type ('AND', 'OR', 'NOT', etc.)\r\n- `x` (Number): X coordinate in pixels\r\n- `y` (Number): Y coordinate in pixels\r\n\r\n**Returns:** Gate object with unique ID\r\n\r\n#### `simulate()`\r\n\r\nExecutes circuit simulation with animated propagation.\r\n\r\n**Algorithm Complexity:** O(d × g) where d is circuit depth and g is gate count\r\n\r\n#### `generateTruthTable()`\r\n\r\nGenerates complete truth table for current circuit.\r\n\r\n**Time Complexity:** O(2ⁿ × g) where n is input count and g is gate count\r\n\r\n### Event System\r\n\r\n```javascript\r\n// Gate events\r\ndocument.addEventListener('gateCreated', (event) =\u003e {\r\n    console.log('New gate:', event.detail.gate);\r\n});\r\n\r\n// Simulation events\r\ndocument.addEventListener('simulationComplete', (event) =\u003e {\r\n    console.log('Results:', event.detail.results);\r\n});\r\n```\r\n\r\n## 🎓 Educational Applications\r\n\r\n### Computer Science Curriculum\r\n\r\n**Digital Logic Design (CS 231):**\r\n\r\n- Boolean algebra visualization\r\n- Gate-level circuit design\r\n- Combinational logic analysis\r\n- Truth table construction\r\n\r\n**Computer Architecture (CS 311):**\r\n\r\n- CPU component design\r\n- ALU implementation\r\n- Control unit logic\r\n- Pipeline stage analysis\r\n\r\n**VLSI Design (CS 431):**\r\n\r\n- Gate-level optimization\r\n- Timing analysis\r\n- Power consumption estimation\r\n- Critical path identification\r\n\r\n### Laboratory Exercises\r\n\r\n#### Exercise 1: Basic Logic Gates\r\n\r\n**Objective:** Understand fundamental gate operations\r\n**Tasks:**\r\n\r\n1. Implement all basic gates\r\n2. Verify truth tables\r\n3. Analyze propagation delays\r\n\r\n#### Exercise 2: Combinational Circuits\r\n\r\n**Objective:** Design complex combinational systems\r\n**Tasks:**\r\n\r\n1. 4-bit adder design\r\n2. Multiplexer implementation\r\n3. Decoder/encoder circuits\r\n\r\n#### Exercise 3: Boolean Minimization\r\n\r\n**Objective:** Optimize circuit complexity\r\n**Tasks:**\r\n\r\n1. K-map simplification\r\n2. SOP/POS conversion\r\n3. Gate count optimization\r\n\r\n### Assessment Integration\r\n\r\n**Automated Grading Support:**\r\n\r\n- JSON export for submission\r\n- Standardized circuit formats\r\n- Performance metrics extraction\r\n\r\n## 🔧 Technical Specifications\r\n\r\n### Browser Compatibility\r\n\r\n| Browser | Version | Support Level |\r\n|---------|---------|---------------|\r\n| Chrome | 80+ | Full Support |\r\n| Firefox | 75+ | Full Support |\r\n| Safari | 13+ | Full Support |\r\n| Edge | 80+ | Full Support |\r\n\r\n### Performance Metrics\r\n\r\n**Maximum Circuit Complexity:**\r\n\r\n- Gates: 1000+ concurrent gates\r\n- Connections: 2000+ wire connections\r\n- Simulation Speed: \u003c100ms for typical circuits\r\n\r\n**Memory Usage:**\r\n\r\n- Base Application: ~2MB\r\n- Per Gate: ~500 bytes\r\n- Per Wire: ~300 bytes\r\n\r\n### Accessibility Features\r\n\r\n**WCAG 2.1 AA Compliance:**\r\n\r\n- Keyboard navigation support\r\n- Screen reader compatibility\r\n- High contrast mode\r\n- Minimum 44px touch targets\r\n\r\n## 🤝 Contributing\r\n\r\n### Development Guidelines\r\n\r\n```bash\r\n# Fork and clone\r\ngit clone https://github.com/galihru/logicsim.git\r\n\r\n# Create feature branch\r\ngit checkout -b feature/new-gate-type\r\n\r\n# Make changes and commit\r\ngit commit -m \"Add BUFFER gate implementation\"\r\n\r\n# Push and create pull request\r\ngit push origin feature/new-gate-type\r\n```\r\n\r\n### Code Standards\r\n\r\n- **ES6+ JavaScript**: Modern syntax and features\r\n- **Semantic HTML5**: Accessible markup\r\n- **CSS3 Variables**: Consistent theming\r\n- **JSDoc Comments**: Comprehensive documentation\r\n\r\n### Testing Requirements\r\n\r\n- Unit tests for all gate logic\r\n- Integration tests for simulation engine\r\n- Cross-browser compatibility testing\r\n- Performance regression testing\r\n\r\n## 📄 License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n## 📞 Support\r\n\r\nFor technical support, educational inquiries, or collaboration opportunities:\r\n\r\n- **Issues**: [GitHub Issues](https://github.com/galihru/logicsim/issues)\r\n- **Discussions**: [GitHub Discussions](https://github.com/galihru/logicsim/discussions)\r\n- **Documentation**: [Wiki](https://github.com/galihru/logicsim/wiki)\r\n\r\n---\r\n\r\n**Version 1.0.0** | **Built with ❤️ for Computer Science Education** | **© 2024 Digital Logic Simulator Team**\r\n\r\n```\r\nY = (A ⊕ B)' = A'B' + AB\r\n```\r\n\r\n## 🧮 Boolean Logic Theory\r\n\r\n### Canonical Forms\r\n\r\n#### Minterm Expansion\r\n\r\nFor a Boolean function of n variables, there are 2ⁿ possible minterms. Each minterm is a product term where each variable appears exactly once (either complemented or uncomplemented).\r\n\r\n**Minterm Formula:**\r\n\r\n```\r\nmᵢ = x₁^(a₁) · x₂^(a₂) · ... · xₙ^(aₙ)\r\n```\r\n\r\nWhere aᵢ ∈ {0, 1} and x^0 = x', x^1 = x\r\n\r\n#### Maxterm Expansion\r\n\r\nSimilarly, maxterms are sum terms where each variable appears exactly once.\r\n\r\n**Maxterm Formula:**\r\n\r\n```\r\nMᵢ = x₁^(b₁) + x₂^(b₂) + ... + xₙ^(bₙ)\r\n```\r\n\r\nWhere bᵢ ∈ {0, 1} and x^0 = x, x^1 = x'\r\n\r\n### Karnaugh Map Simplification\r\n\r\nFor Boolean function minimization, the simulator implements Karnaugh map logic for optimal circuit reduction:\r\n\r\n**K-map Adjacency Rule:**\r\nTwo cells are adjacent if they differ in exactly one variable position.\r\n\r\n**Grouping Rules:**\r\n\r\n- Groups must contain 2ⁿ cells (1, 2, 4, 8, 16, ...)\r\n- Groups should be as large as possible\r\n- Each group eliminates one variable from the resulting term\r\n\r\n### Functional Completeness\r\n\r\nThe simulator supports functionally complete gate sets:\r\n\r\n- **{NAND}**: Universal gate set\r\n- **{NOR}**: Universal gate set\r\n- **{AND, OR, NOT}**: Standard complete set\r\n\r\n**Proof of NAND Universality:**\r\n\r\n```\r\nNOT A = A NAND A\r\nA AND B = (A NAND B) NAND (A NAND B)\r\nA OR B = (A NAND A) NAND (B NAND B)\r\n```\r\n\r\n## 📊 Circuit Analysis\r\n\r\n### Propagation Delay Analysis\r\n\r\nThe simulator models realistic gate delays using discrete event simulation:\r\n\r\n**Delay Calculation:**\r\n\r\n```\r\ntpd = tpd_gate + tpd_interconnect\r\n```\r\n\r\nWhere:\r\n\r\n- tpd_gate: Intrinsic gate delay\r\n- tpd_interconnect: Wire routing delay\r\n\r\n### Critical Path Analysis\r\n\r\nFor combinational circuits, the critical path determines maximum operating frequency:\r\n\r\n**Critical Path Delay:**\r\n\r\n```\r\nTcritical = max(Σ tpd_gates_in_path)\r\n```\r\n\r\n**Maximum Frequency:**\r\n\r\n```\r\nfmax = 1 / (Tcritical + tsetup + thold)\r\n```\r\n\r\n### Signal Integrity\r\n\r\nThe simulator considers:\r\n\r\n- **Rise/Fall Times**: Signal transition characteristics\r\n- **Noise Margins**: VIH, VIL, VOH, VOL specifications\r\n- **Fan-out Loading**: Current driving capability analysis\r\n\r\n### Circuit Complexity Metrics\r\n\r\n**Gate Count Complexity:**\r\n\r\n```\r\nComplexity = Σ (Gate_Inputs × Gate_Weight)\r\n```\r\n\r\n**Logic Depth:**\r\n\r\n```\r\nDepth = max(levels_from_input_to_output)\r\n```\r\n\r\n## 🏗️ System Architecture\r\n\r\n### Frontend Architecture\r\n\r\n```\r\n┌─────────────────────────────────────┐\r\n│           User Interface            │\r\n├─────────────────────────────────────┤\r\n│     Drag \u0026 Drop Engine              │\r\n├─────────────────────────────────────┤\r\n│     Circuit Simulation Engine       │\r\n├─────────────────────────────────────┤\r\n│     Boolean Logic Processor         │\r\n├─────────────────────────────────────┤\r\n│     Canvas Rendering System         │\r\n└─────────────────────────────────────┘\r\n```\r\n\r\n### Class Hierarchy\r\n\r\n```javascript\r\nDigitalLogicSimulator\r\n├── Gate Management\r\n│   ├── createGate()\r\n│   ├── deleteGate()\r\n│   └── calculateGateOutput()\r\n├── Wire Management\r\n│   ├── createWire()\r\n│   ├── updateWires()\r\n│   └── deleteWire()\r\n├── Simulation Engine\r\n│   ├── simulate()\r\n│   ├── animatedPropagation()\r\n│   └── calculateGateLevels()\r\n└── Export Systems\r\n    ├── generateVerilog()\r\n    ├── generateTruthTable()\r\n    └── saveDesign()\r\n```\r\n\r\n### Data Structures\r\n\r\n**Gate Object Structure:**\r\n\r\n```javascript\r\n{\r\n    id: String,           // Unique identifier\r\n    type: String,         // Gate type (AND, OR, NOT, etc.)\r\n    x: Number,           // X coordinate\r\n    y: Number,           // Y coordinate\r\n    inputCount: Number,  // Number of inputs\r\n    inputValues: Array,  // Current input states\r\n    outputValues: Array, // Current output states\r\n    element: HTMLElement // DOM reference\r\n}\r\n```\r\n\r\n**Wire Object Structure:**\r\n\r\n```javascript\r\n{\r\n    id: String,              // Unique identifier\r\n    sourceGate: String,      // Source gate ID\r\n    targetGate: String,      // Target gate ID\r\n    sourcePinIndex: Number,  // Source pin index\r\n    targetPinIndex: Number,  // Target pin index\r\n    element: SVGElement      // SVG path element\r\n}\r\n```\r\n\r\n### Progressive Web App Implementation\r\n\r\n**Service Worker Features:**\r\n\r\n- **Caching Strategy**: Cache-first with network fallback\r\n- **Offline Support**: Full functionality without internet\r\n- **Background Sync**: Circuit data synchronization\r\n- **Push Notifications**: Educational reminders (future feature)\r\n\r\n**Manifest Configuration:**\r\n\r\n```json\r\n{\r\n    \"name\": \"Digital Logic Simulator\",\r\n    \"short_name\": \"Logic Sim\",\r\n    \"start_url\": \"./\",\r\n    \"display\": \"standalone\",\r\n    \"theme_color\": \"#667eea\",\r\n    \"background_color\": \"#f8fafc\"\r\n}\r\n```\r\n\r\n4. **Organize**: Drag gates around to organize your circuit layout\r\n\r\n### 2. Setting Inputs\r\n\r\n- Use the input controls panel to toggle input values (0 or 1)\r\n- Input gates will change color to indicate their state\r\n\r\n### 3. Running Simulation\r\n\r\n1. Click the **Simulate** button to run the circuit simulation\r\n2. Watch as signals propagate through your circuit\r\n3. Active wires and gates will be highlighted in green\r\n4. Check the simulation results panel for detailed output\r\n\r\n### 4. Analyzing Results\r\n\r\n- **Truth Table**: View complete truth table for all input combinations\r\n- **Simulation Output**: See current state of all gates and signals\r\n- **Visual Feedback**: Active components are highlighted\r\n\r\n### 5. Generating Code\r\n\r\n1. Click **Generate Verilog** to create HDL code\r\n2. The generated code appears in the Verilog panel\r\n3. Use **Copy Code** to copy the Verilog to your clipboard\r\n4. Use this code in HDL simulators or synthesis tools\r\n\r\n### 6. Saving Your Work\r\n\r\n- **Save Design**: Export your circuit as a JSON file\r\n- **Load Design**: Import previously saved circuits\r\n- Designs include gate positions, connections, and input states\r\n\r\n## Technical Details\r\n\r\n### Circuit Simulation Engine\r\n\r\n- **Propagation Algorithm**: Multi-iteration signal propagation\r\n- **Combinational Logic**: Supports complex combinational circuits\r\n- **State Management**: Tracks input/output states of all components\r\n- **Connection Validation**: Prevents invalid connections (output-to-output, etc.)\r\n\r\n### Verilog Code Generation\r\n\r\n- **Module Structure**: Generates proper Verilog module syntax\r\n- **Wire Declarations**: Automatic wire declarations for internal signals\r\n- **Gate Instantiation**: Uses Verilog primitive gates\r\n- **Port Mapping**: Correct input/output port assignments\r\n\r\n### File Formats\r\n\r\n- **Design Files**: JSON format containing gate positions and connections\r\n- **Generated Code**: Standard Verilog HDL (.v files)\r\n\r\n## Browser Compatibility\r\n\r\n- Modern browsers with HTML5 Canvas support\r\n- Chrome, Firefox, Safari, Edge\r\n- Responsive design for desktop and tablet use\r\n\r\n## Educational Applications\r\n\r\n- **Digital Logic Courses**: Learn basic logic gate operations\r\n- **Computer Architecture**: Understand building blocks of processors\r\n- **Circuit Design**: Practice designing combinational logic circuits\r\n- **HDL Learning**: Bridge between visual design and code\r\n- **Truth Table Analysis**: Understand Boolean logic relationships\r\n\r\n## Tips for Use\r\n\r\n1. Start with simple circuits (few gates) before building complex designs\r\n2. Use the truth table to verify your circuit behavior\r\n3. Organize your layout before making connections\r\n4. Save your designs frequently\r\n5. Use the generated Verilog code in simulators like ModelSim or Vivado\r\n\r\n## Future Enhancements\r\n\r\n- Sequential logic support (flip-flops, latches)\r\n- Timing analysis and delay simulation\r\n- Sub-circuit modules and hierarchical design\r\n- Advanced analysis tools (critical path, power analysis)\r\n- Integration with HDL simulators\r\n\r\n---\r\n\r\n**Built for educational purposes to help students understand digital logic design and the relationship between visual circuit representation and HDL code.**\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalihru%2Flogicsim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgalihru%2Flogicsim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgalihru%2Flogicsim/lists"}