$ show djhworld/simple-computer
This repository implements a complete 16-bit computer simulator built from fundamental logic gates (NAND, AND, OR, etc.) in Go. It includes a CPU, memory, ALU, memory-mapped I/O (keyboard and 240Γ160 pixel display), and a custom instruction set. The project provides three command-line tools: a simulator that loads binary programs and runs them with a GLFW-based graphical window, an assembler that converts a custom assembly language into binary, and a program generator that produces example assembly programs (e.g., text writer, sine wave animation, snake brush). The system is a faithful gate-level simulationβevery component from bits to the CPU is wired together using Go structs, making it an educational tool for understanding computer architecture.
The LLM identified 4 files worth highlighting for reuse:
Defines the fundamental logic gates (NAND, AND, OR, XOR, NOT, NOR) as Go structs with Update and Output methods. Each gate is a self-contained component that can be wired together. This pattern is clean, testable, and reusable in any digital logic simulation project requiring gate-level primitives.
Implements a two-pass assembler for a custom 16-bit instruction set. It supports labels, symbols, built-in symbols (CURRENTINSTRUCTION, NEXTINSTRUCTION), and outputs little-endian binary. The assembler is well-structured with clear separation of parsing, label resolution, and instruction emission, making it a reusable blueprint for assembling custom instruction sets.
Defines the Peripheral interface with Connect and Update methods, providing a clean abstraction for memory-mapped I/O devices. This pattern allows the keyboard and display adapters to be independently developed and tested, and can be reused in any system that needs pluggable I/O components.
Implements a family of decoders (2x4, 3x8, 4x16, 8x256) using the component wiring pattern. These decoders are building blocks for memory addressing and instruction decoding. The implementation is clean and parameterized, making it directly reusable in other digital design projects that require decoders.