MOS digital simulations using Lua
Overview
The chip tracing software simulation mode can be extended using Lua scripts.
With Lua scripts it is possible to:
- Read or write signals from the simulator.
- Find any signal location with only a component name.
- Control the simulator.
- Create user interfaces to intuitively control the behavior of the script.
- And more, by using the full potential of the exposed APIs.
Getting started
Scripts have to be placed in the folder ‘scripts/simulation/’.
To select a script and launch the simulation mode, press (Ctrl) + F1.
Its path will be memorized by the sofware (even if you close it).
Then you can quickly launch the simulation using the memorized script with (Shift) + F1.
Controls:
- F1: Launch simulation.
- (Control) + F1: Select script and launch simulation with Lua.
- (Shift) + F1: Quickly launch simulation with Lua.
Note: It will use the previously selected script.
Making scripts
Simulation scripts are simple tables with at least some callback functions:
- callback_create: will be called at start of the simulation.
Used mainly to initialise variables and find nodes. - callback_update: the update loop of the simulation mode.
Used to control the simulator by sending signals, update UI, etc…
Here a basic template:
local sim = {
timer = 0
}
function sim.callback_create(editor)
-- initialize inputs
local proxy = editor:proxy()
for i=0, proxy:inputsCount()-1 do
proxy:writeInput(i, false)
end
proxy:simulate()
sim.timer = 0
sim.timer_max = 10
end
function sim.callback_update(editor, dt)
if(sim.wait(dt)) then
return
end
local proxy = editor:proxy()
-- place signal updates here
proxy:simulate()
end
function sim.wait(dt)
sim.timer = sim.timer - dt
if(sim.timer > 0) then
return true
end
sim.timer = sim.timer_max
return false
end
return simIntel 4004 CPU demo
This demo allows you to simulate the intel 4004 at a transistor level with an emulated rom (Intel 4001).
Limitations: No RAM, no I/O expanders (4003), only the 4004 CPU and an emulated rom.

Screenshot of the running simulation.
Focus on the registers and their content.
Features:
- Initialization sequence to boot the 4004.
- Intel 4001 emulation to run programs.
- A simple UI to control the simulation.
- Registers are read directly from the circuit in realtime.
Downloads:
Usage: Put the lua file in scripts/simulation/ and the save.json file in the program folder.
Public API
Todo