r/typescript • u/kottbusser_floor • 23d ago
Designing hardware in Typescript
Simten is an open source (https://github.com/simtenHQ/simten) HDL where circuits are written in TypeScript. The simulator is Ts as well, so everything runs in-process in Node or the browser.
I built a game around it to showcase the platform, https://play.simten.dev/
So essentially write a circuit in the editor to match the spec, it simulates live on the canvas on the right. You can toggle inputs, step the clock back/forward, drill into parts to view internals etc.
Here is the basic syntax for a half adder (GIF shows a full adder built from two of these):
import { bit, circuit } from '@simten/core'
import { And, Xor } from '@simten/core/std'
const HalfAdder = circuit('HalfAdder', {
inputs: { a: bit, b: bit },
outputs: { sum: bit, carry: bit },
nodes: { xor: Xor, and: And },
connect: ({ inputs, outputs, nodes: { xor, and } }) => [
inputs.a.to(xor.a, and.a),
inputs.b.to(xor.b, and.b),
xor.out.to(outputs.sum),
and.out.to(outputs.carry),
],
})You can also run circuits headlessly in node:
import { simulate } from '@simten/core'
const sim = simulate(HalfAdder)
sim.set({ a: 1, b: 1 })
sim.read() // { sum: 0, carry: 1 }Because it's all in-process, you can use npm packages at the transpile step. For example, this calls figlet to bake ASCII art into a ROM and streams it to a console (press play in the bottom left and change "Simten" text on line 7 ): https://simten.dev/circuit?example=figlet
For when you are sick or typing there's an mcp server, so you can ask your assistant for a circuit and it writes it, tests it and opens it for you to view. Passing it proper hardware specs I have built RISC-V cpus with it among other things. it has been a great learning experience building it. Feedback and/or contributions welcome!
2
u/Goodassmf 22d ago
Wow. So cool. So its like a game you need to complete the schematics to learn how to use the library?