ND500X Emulator¶
A Norsk Data ND-500 CPU emulator written in C11
New: ND-500 opcode matrix - every opcode on one page, with filters. Also: the ND-5000 '87 extension instructions, instruction set overview, all instructions.
Overview¶
ND500X is an emulator for the Norsk Data ND-500 architecture, featuring:
- Accurate CPU emulation with full register set (PC, FLAGS, I/A/E registers, etc.)
- O(1) instruction dispatch with opcode-indexed function pointer table for million-per-second execution
- Modular instruction architecture with 241 functions organized in 13 class-based directories
- Byte-addressed memory with bus interface
- 14 addressing modes including short forms, extended modes, and special modifiers
- Interactive CLI debugger with memory inspection, disassembly, and step-through execution
- Professional tab completion with context-aware command and subcommand completion
- Command history with arrow key navigation and persistent storage
- Breakpoints and Watchpoints for advanced debugging (PC-based, memory read/write/change)
- Advanced debugging features including conditional breakpoints, instruction tracing, performance profiling, and call stack tracking
- WebAssembly support for browser-based emulation
- Instruction code generation from JSON specification (1078 instruction variants, 241 unique functions)
- Debug Adapter Protocol (DAP) server for IDE-driven debugging (VS Code and other DAP clients): breakpoints, data breakpoints (memory and register watchpoints), full ND-500 register file as variables, memory read/write, disassembly and console I/O - see docs/DAP_INTEGRATION.md
Table of Contents¶
- Download
- Quick Start
- Building
- Testing
- Usage
- Architecture
- Dependencies
- Platform Support
- Project Structure
- Contributing
- License
Download¶
Pre-built binaries are published on the Releases page - latest release.
| Platform | File | Notes |
|---|---|---|
| Windows x64 | nd500x-windows-x64.zip |
Standalone .exe, no DLLs to install |
| Windows x86 | nd500x-windows-x86.zip |
32-bit build |
| Linux amd64 | nd500x_<version>_amd64.deb |
sudo dpkg -i nd500x_*.deb |
| Linux arm64 | nd500x_<version>_arm64.deb |
Raspberry Pi OS 64-bit (Pi 3/4/5) |
| Linux armhf | nd500x_<version>_armhf.deb |
Raspberry Pi OS 32-bit (Pi 2/3/4/Zero 2) |
| macOS arm64 | nd500x-macos-arm64.tar.gz |
Apple Silicon |
| macOS x86_64 | nd500x-macos-x86_64.tar.gz |
Intel |
Each release is built by
.github/workflows/release.yml from the tagged
commit. To cut one, push a tag starting with v:
git tag -a v0.2.0 -m "Release 0.2.0"
git push origin v0.2.0
The binaries carry no runtime dependencies: cJSON is compiled in, and the Windows builds are statically linked.
Note: no release has been published yet. The workflow cannot run until the
external/ndmonlibsubmodule repository is public -actions/checkoutfails to clone it otherwise. Until then, build from source as below; the macOS targets in particular have never been built.
Quick Start¶
# Clone the repository
git clone https://github.com/RetroCoreLabs/nd500x.git
cd nd500x
# Build and run (using Makefile wrapper)
make
make run
# Or build with CMake directly
mkdir -p build && cd build
cmake ..
make
./bin/nd500x --debug
Building¶
Prerequisites¶
Native Build:
- CMake 3.16+
- C11-compatible compiler (GCC or Clang; on Windows use MinGW - MSVC is untested)
- pthread (supplied by winpthreads under MinGW, by libSystem on macOS)
- libcjson - optional. It is a hard requirement of the code, but CMake downloads and compiles a private copy when the system has none, so nothing needs installing.
- libreadline - optional, adds tab completion and history to the
--debugREPL
WebAssembly Build:
- Emscripten SDK
- CMake 3.16+
Native Build¶
Using the Makefile wrapper (Linux and macOS):
make # Build the project
make release # Optimised build into build_release/ - what releases ship
make run # Build and run with --debug flag
make clean # Clean build artifacts
On Windows, use the batch wrapper instead - it puts w64devkit on PATH for the build only and forces the Ninja generator (left alone, CMake picks the Visual Studio generator, which needs MSVC and cannot drive MinGW):
build.bat :: release build -> build_release\bin\nd500x.exe
build.bat debug :: debug build -> build\bin\nd500x.exe
build.bat clean :: remove both build directories
C:\Utils\w64devkit; set W64DEVKIT to override.
Using CMake directly:
mkdir -p build
cd build
cmake ..
make
The native build will:
- Auto-generate instruction tables from
instructions.json - Compile all libraries and the main executable
- Output binary to
build/bin/nd500x
Note: In-source builds are not allowed. Always use a separate build directory.
WebAssembly Build¶
Using the Makefile wrapper:
make wasm # Build WASM target
make wasm-clean # Clean WASM build
Using CMake directly:
mkdir -p build_wasm
cd build_wasm
emcmake cmake -DBUILD_WASM=ON ..
make
The WASM build automatically:
- Fetches cJSON via CMake FetchContent
- Exports JavaScript-callable functions for debugging
- Configures Emscripten with proper memory and export settings
- Copies web interface files to build output
WebAssembly Debugger¶
The WASM build includes a complete web-based debugger interface:
Build and Run:
make wasm-serve # Build WASM and start web server
This will:
- Build the WebAssembly version with debugger support
- Start a local web server on http://localhost:8000
- Open your browser to use the debugger
Web Debugger Features:
- File Upload: Load .o/.out files via file picker or drag-and-drop
- Modern Three-Panel Layout: Disassembly (left), registers/TRAP/memory (right)
- JSON-Based Disassembly: Structured output with address, bytes, mnemonic, operands
- Interactive Registers: Click any register to edit value (hex or decimal input)
- PC-Synchronized Disassembly: Changing PC automatically updates disassembly view
- TRAP Information Panel: Real-time trap display with clear traps button
- Clickable Memory Addresses: Click addresses to navigate memory view
- Enhanced Breakpoints: Click gutter to toggle, visual dots without content shifting
- Color-Coded Disassembly: ANSI-inspired colors (blue mnemonics, magenta branches)
- Step/Run Controls: Single-step execution or continuous running
- Memory Viewer: Hex dump with ASCII representation
- Real-time Updates: Live register, trap, and disassembly updates during execution
Browser Compatibility:
- Modern browsers with WebAssembly support (Chrome 57+, Firefox 52+, Safari 11+)
- No external dependencies - pure vanilla JavaScript
- Responsive design works on desktop and mobile
Usage:
- Run
make wasm-serve - Open http://localhost:8000 in your browser
- Load a .o or .out file using the "Load File" button or drag-and-drop
- Use Step/Run controls to execute code
- Click registers to edit values (PC changes update disassembly)
- Click breakpoint gutter (left of address) to toggle breakpoints
- Click memory addresses to navigate to new memory locations
- View traps in real-time and clear them with the clear button
- Enjoy color-coded disassembly with proper spacing and alignment
Testing¶
The emulator includes a comprehensive test suite with 37,298 instruction validation tests covering all ND-500 instruction classes.
Running Tests¶
# Run all instruction validation tests
./build/bin/test_conformance
# Run with --continue to see all failures (don't stop on first)
./build/bin/test_conformance --continue
# Filter tests by instruction name
./build/bin/test_conformance --filter comp
./build/bin/test_conformance --filter scomp
# Run a subset of tests
./build/bin/test_conformance --start 100 --count 50
# Run all tests via ctest
cd build && ctest -V
Test Coverage¶
| Instruction Class | Tests | Coverage |
|---|---|---|
| ARITHMETIC | 8,500+ | add, sub, mul, div, inc, dec, neg, abs |
| MOVE | 6,200+ | mov, swap, push, pop, assign |
| BRANCH | 4,800+ | go, if=go, if |
| COMPARE | 2,100+ | comp, comp2, test, pcomp, scomp |
| LOGICAL | 1,900+ | and, or, xor, not |
| SHIFT | 1,400+ | shl, shr, rol, ror |
| CALL | 1,200+ | call, callg, ent, ret |
| FLOAT_MATH | 800+ | fadd, fsub, fmul, fdiv, fconv |
| STRING | 600+ | smove, scomp, sfill |
| BITFIELD | 500+ | getb, putb, getbi, putbi |
| CONTROL | 400+ | tset, clr, init, bp |
| SYSTEM | 300+ | various system instructions |
Negative Test Infrastructure¶
The test suite includes 3,509 negative tests that verify the test framework correctly detects validation failures:
- 1,789 wrong flag tests - Intentionally incorrect status flags
- 1,717 wrong register tests - Intentionally incorrect register values
- 3 wrong memory tests - Intentionally incorrect memory values
Negative tests ensure the validation logic catches real bugs and doesn't produce false positives.
Test JSON Format¶
Tests are defined in test/nd500-conformance.json with this structure:
{
"name": "ADD_W_Positive_PlusPositive",
"assembly": "w add i1,$100",
"bytes": [16, 197, 100, 0],
"initial": {
"regs": { "pc": 4096, "i1": 50 }
},
"final": {
"regs": { "pc": 4100, "i1": 150, "st": 64 }
}
}
For negative tests, additional fields mark expected failures:
{
"isNegativeTest": true,
"negativeTestType": "wrong_flag",
"expectedValidationFailure": "st:Z"
}
Usage¶
Running the Emulator¶
./build/bin/nd500x --debug
Command-Line Options¶
| Option | Description |
|---|---|
--monitor |
Start the SINTRAN-flavoured shell (log in, run DOM programs by name) |
--telnet <port> |
Serve the SINTRAN shell over TCP/telnet on <port> (implies --monitor) |
--script <path> |
Feed shell commands from a file, then continue interactively (with --monitor) |
--config <path> |
Load settings from an ini file (else ./nd500x.ini if present) |
--sintran-root <path> |
SINTRAN file-system root directory (default: current directory) |
--user <name> |
Current SINTRAN user (auto-logged-in by the shell) |
--debug |
Start interactive debugger REPL |
--dap [port] |
Start DAP server for IDE debugging (default port 4500) |
-i <path> |
Load ND-500 a.out file at startup |
--aout <path> |
Load ND-500 a.out file at startup |
--dom <path> |
Load DOM file |
--args <string> |
Set command buffer (program arguments) |
--pc <addr> |
Override starting PC address |
--run |
Run program non-interactively (exit on MON 0B or error) |
--max-steps <n> |
Maximum instructions to execute (default: unlimited) |
--trace-file <path> |
Write instruction trace to file |
-ansi |
Force-enable ANSI color output (even when piped) |
-noansi |
Force-disable ANSI color output |
--disasm <len> |
Disassemble |
--addr <addr> |
Start address for disassembly |
--hexdump <len> |
Hex dump |
Batch Execution with Trace:
Run a DOM program and capture instruction trace to a file:
./build/bin/nd500x --dom program.dom --run --trace-file trace.txt
./build/bin/nd500x --dom program.dom --run --max-steps 10000 --trace-file trace.txt
Using the test harness with radix option:
./build/bin/test_dom_integration program.dom 10000 --trace-file trace.txt --radix hex
The trace file contains executed instructions with register state. MON calls (CALL to segment 31) are annotated with octal number and name:
0x08000004 C3 08 02 D4 47 00 call $0x802D447,$0x0 | I1[00000000] ... |
-> L=0800000A
0x0802D447 9C entd | I1[00000000] ...
0x0802D44F C3 F8 00 00 09 00 call $0xF8000009,$0x0 | I1[00000000] ... | MON 11B [TIME/GetBasicTime]
0x0802D1CC C3 F8 00 00 1A 01 C4 08 01 D7 F8 call $0xF800001A,$0x1,$0x801D7F8 | I1[0801D89E] ... | MON 32B [MSG/OutMessage]
Trace format:
- PC address - Instruction location
- Instruction bytes - Up to 12 bytes on one line (includes CALL argument addresses)
- Disassembly - Mnemonic and operands (left-aligned, 60 chars wide)
- Registers - I1-I4, flags [PDZSCKO], B, L, R, TOS before execution
- MON annotation - For CALL $0xF8xxxxxx:
| MON nnnB [short/long] - Register changes - Line starting with
->shows registers modified by instruction
Color Output:
- By default, color output is automatically detected based on TTY and terminal type
- When output is redirected to a file or pipe, colors are automatically disabled
- Use
-ansito force colors on, or-noansito force them off
Color Scheme:
- Gray - Memory addresses
- Yellow - Hex byte codes
- Green - Instructions (mov, add, sub, etc.)
- Red - Branch/jump instructions (go, if>=go, etc.)
- White - Operands and registers
- Cyan - Labels and symbols
- Blue - Comments
SINTRAN Shell (Monitor Mode)¶
--monitor starts a SINTRAN-flavoured command shell: an @ prompt you log in to,
run DOM (:DOM) programs from by name, and log out of. The command surface is
sourced from the ND-60.128.5 SINTRAN III Reference Manual; see
docs/SINTRAN-SHELL-SPEC.md.
# Local terminal, pointing at a directory that holds your programs
./build/bin/nd500x --monitor --sintran-root ./sintran
Where programs live. The shell resolves a program name under the SINTRAN root
(--sintran-root, default: the directory you launch from):
<root>/<USER>/<NAME>.DOM (searched first, after you log in)
<root>/SYSTEM/<NAME>.DOM (searched next)
So put your .DOM files in <root>/SYSTEM/ or <root>/<USER>/ and run them by
name. The example below uses a SINTRAN user area with the vendor programs
staged in SYSTEM/ - the ND linker, compiler and their support files. That
tree is far too large to commit, so it lives outside the repository;
docs/PATH_CONVENTIONS.md records it as $ND500USERS and make doctor
reports whether this checkout can reach it.
$ ./build/bin/nd500x --monitor --sintran-root ~/ND500USERS
SINTRAN III (nd500x) - user SYSTEM. Type HELP for commands.
@ login GUEST
User GUEST logged in.
@ list-files
@ recover-domain BPROG # or just: BPROG
-- program exited (15374 instructions) --
@ logout
Commands (abbreviate to any unique prefix, e.g. LI-FI for LIST-FILES;
type HELP for the list):
| Command | Purpose |
|---|---|
LOGIN <user> |
Log in (simplified; switches the current user) |
LOGOUT |
End the session |
RECOVER-DOMAIN <name> / <name> |
Load and run a DOM by name |
LIST-FILES |
List files in the current user's and SYSTEM's directories |
SET-TERMINAL-TYPE [<term>],<type> |
Set the terminal type; with no type, lists the types defined in the system's .VTM file |
GET-TERMINAL-TYPE |
Show the current terminal type |
HELP [<command>] |
List commands |
EXIT |
Leave the emulator |
The terminal type is stored in the emulator's per-terminal state (the same value
SET-TERMINAL-TYPE/GET-TERMINAL-TYPE monitor calls use), so a running program
that queries it sees what you set. Type names are read from the system's .VTM
file, never hardcoded.
Telnet (connect a TDV/VT terminal over TCP):
./build/bin/nd500x --telnet 4600 --sintran-root ./sintran
# then from anywhere:
telnet <host> 4600
Config file. Instead of flags, put settings in nd500x.ini (auto-loaded from
the current directory, or pass --config <path>). Command-line flags override it:
# nd500x.ini
sintran-root = ./sintran
user = GUEST
terminal-type = 6
telnet-port = 4600
Scripted / batch: --script <file> feeds shell commands from a file (one per
line, a leading @ is allowed) before returning to interactive input — useful for
reproducible sessions.
Convenience launcher (~/run_500.sh). A wrapper script outside the repo
that always runs the current build against a fixed config:
#!/usr/bin/env bash
ND500X=build/bin/nd500x
CONFIG=build/test_sintran/nd500x.ini
[ -n "$1" ] && exec "$ND500X" --telnet "$1" --config "$CONFIG" \
|| exec "$ND500X" --monitor --config "$CONFIG"
Usage: ~/run_500.sh (local terminal) or ~/run_500.sh <port> (telnet, then
telnet localhost <port>). Its config,
build/test_sintran/nd500x.ini, is NOT committed
(everything under build/ is a build artifact) — if it's missing, rebuild it
from the ini format above. A working example, pointing sintran-root at a
populated SINTRAN user area outside the repository:
# build/test_sintran/nd500x.ini
sintran-root = ~/ND500USERS
user = GUEST
terminal-type = 53
sintran-root expands a leading ~, so the line above works on any machine
without naming one. It does not expand $VAR, so an environment variable
cannot be used inside the ini itself; $ND500USERS in
docs/PATH_CONVENTIONS.md records where that tree
lives, and make doctor reports whether this checkout can reach it.
Point it somewhere with files in it. The repo root will not do: GUEST/,
SYSTEM/ and SCRATCH/ exist there but hold nothing tracked, so on a fresh
clone all three are empty and nothing resolves — not RECOVER-DOMAIN/@<name>
against <root>/SYSTEM/, and not source files under <root>/GUEST/. A user
area needs .DOM files staged in SYSTEM/ before name lookups work; see
docs/RUN_500_SH_CONFIG_RECONSTRUCTION.md
for the full story.
Debugger Commands¶
The interactive debugger supports 60+ commands for memory inspection, disassembly, execution control, breakpoints, watchpoints, MMU control, MON call debugging, and more.
For complete command reference, see: docs/DEBUGGER_COMMAND_REFERENCE.md
Quick Reference¶
| Category | Commands |
|---|---|
| Memory | m, mp, m!, msym |
| Disassembly | d, dis, dsym |
| Execution | step/s, run, stop, continue/c, status |
| Registers | regs, set |
| Loading | load, loaddom, loadmap, loadsrc |
| Symbols | symb, goto, segments |
| Breakpoints | bp (set/list/del/enable/disable/cond/source) |
| Watchpoints | wp (set/list/del/enable/disable/reg) |
| Display Options | show trace/memtrace/ea/hex/demangle/source/profile/trap/mmu |
| Profiling | profile show/reset |
| Call Stack | backtrace/bt, stackframe/sf |
| MMU Control | mmu, showmmu, phyladr, showcap, showpages, memmap, listpst, listpcb, dumppt |
| Domains | domain, unload, domverify |
| MON Calls | mon log/status/list/info/break |
| Utility | help, history, clear-traps, q/quit |
Tab Completion and History¶
- Tab completion: Context-aware command and subcommand completion
- Command history: Arrow keys, persistent storage in
~/.nd500x_history - History shortcuts:
!!(last),!nnn(by number),!string(search)
Example Session¶
$ ./build/bin/nd500x --debug
[00000000] loaddom /path/to/program.dom
PC set to start address: 0x08000004
[08000004] bp 0x08001000
Breakpoint 0 set at 0x08001000
[08000004] run
running...
Stopped: Breakpoint at 0x08001000
[08001000] regs
PC=08001000 FLAGS=00000000
I1/W1=00000000 ...
[08001000] show trace on
show trace: on
[08001000] step 5
0x08001000 C3 08 02 D4 47 00 call $134403143,$0
...
Stepped 5 instructions
[08001006] q
DAP Debugging (IDE Integration)¶
The emulator includes a Debug Adapter Protocol server, so it can be debugged from VS Code or any other DAP client instead of (or alongside) the CLI REPL.
Default port: 4500 (the sibling nd100x emulator uses 4711, so both can run at the same time).
Start the server:
# Headless: load a DOM and serve DAP until the client disconnects.
# The CPU stays stopped until the client sends continue.
./build/bin/nd500x --dom program.dom --dap # port 4500
./build/bin/nd500x --dom program.dom --dap 4600 # explicit port
# Or from the interactive REPL (DAP runs alongside the CLI):
./build/bin/nd500x --debug
nd500> dap
What the client gets:
- Execution control: continue, step, pause, stopped events with reasons
(
breakpoint,data breakpoint,step,pause,exceptionfor CPU traps) - Instruction breakpoints and source breakpoints (when symbol/source maps
are loaded), sharing the same engine as the CLI
bpcommand - Data breakpoints: memory read/write/readWrite watchpoints on virtual (MMU-translated) or physical addresses, plus break-on-change register watches for PC, I1-I4, L, B, R
- The full ND-500 register block as variables, mirroring the CLI
regsreport: Core (PC, FLAGS, ST1/ST2, PDZSCKO flag string), Integer I1-I4, Float A1-A4/E1-E4 with computed D1-D4 doubles, Addressing L/B/R, Special TOS/LL/HL/THA, MMU/Domain CED/CAD/PS/PSTP/DITBASE, and Trap Control OTE/CTE/MTE/TEMM - all writable via setVariable (except computed values) - Memory read/write (base64 per the DAP spec) with
phys:,dspace:andispace:address-space prefixes; debugger access never triggers watchpoints - Disassembly, expression evaluation (registers, symbols, literals), symbol listing, and console I/O (send keyboard input to the running program, receive its output as DAP output events)
Documentation:
- docs/DAP_INTEGRATION.md - architecture, address spaces, dataId contract, scopes, build notes
- docs/DAP_COMMAND_TEST_MATRIX.md - every supported command with usage variants and live test results
- docs/DAP_BUG_REPORTS.md - behaviour reports from client sessions
Unit tests for the adapter run as part of ctest (test name dap_adapter).
Building without DAP: make without-dap.
ND-500 A.out File Format Support¶
The emulator supports loading ND-500 a.out format files with full symbol table parsing:
File Type Detection:
- Automatically distinguishes between object files (.o) and executables
- Object files: Detected by presence of relocations or placeholder entry point (0x4)
- Executables: No relocations and valid entry point
- Object files are loaded but entry point is set to 0 (cannot execute unlinked code)
Symbol Table:
- Parses 24-byte symbol entries with proper padding
- Displays symbol types: TEXT|EXT, DATA|EXT, BSS|EXT, UNDF|EXT
- Shows symbol values, descriptors, and string table
- Use
symbcommand to list all loaded symbols
Disassembler Features:
- Hex byte display for each instruction (e.g.,
C2 5B 00 00 00 go $91) - Proper operand size detection (handles all size prefixes: bi, by, h, w, f, d)
- Correct decoding of complex instructions (branches, calls, extended addressing)
- Matches nd500-dis reference output
Architecture¶
Core Components¶
┌─────────────────────────────────────────────────┐
│ Frontend │
│ (native: nd500x.c, WASM: main.c) │
└────────────────┬────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Debugger │
│ (REPL, DAP adapter) │
└────────────────┬────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Machine (Debug API) │
│ (memory, bus, unified debug interface) │
└──────┬──────────────────────────┬───────────────┘
│ │
▼ ▼
┌─────────────┐ ┌─────────────────────┐
│ CPU │ │ I/O & Loader │
│ (state, │ │ (machine_loader, │
│ decode, │◄──────────┤ debug_api) │
│ execute) │ └─────────────────────┘
└─────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Instruction Tables │
│ (nd500_instructions.h / nd500_instructions.c)│
│ Pre-generated from instructions.json and │
│ COMMITTED as source - edit the .c directly, │
│ there is no build-time generation step. │
└──────────────────────────────────────────────┘
Key Features¶
Instruction Dispatch Architecture:
- O(1) Dispatch Table: 65,536-entry sparse array indexed by opcode (1,078 populated entries)
- Modular Implementation: 241 unique instruction functions organized by class:
- ARITHMETIC (55), MOVE (48), SYSTEM (26), CALL (17), STRING (15), BRANCH (15)
- FLOAT_MATH (25), COMPARE (4), BITFIELD (6), LOGICAL (6), SHIFT (5), CONTROL (7), IO (1)
- Auto-Generated Stubs: Build-time code generator creates stub files (never overwritten)
- Fast Execution: Function pointer dispatch enables million-per-second instruction execution
- Safe Fallback: NULL dispatch entries trigger illegal instruction trap instead of crashes
Instruction Dispatch Table:
instructions.json(424KB+) defines the ND-500 instruction set- Pre-generated dispatch table (
src/cpu/nd500_instructions.{c,h}) committed to repository - 241 instruction stubs organized in
src/cpu/instructions/<CLASS>/<FunctionName>.c - Each stub includes documentation, operand helpers, and implementation notes
- CPU uses O(1) opcode-indexed lookup for instant instruction execution
ND-500 Addressing Modes (14 modes):
- Short forms: CONSTANT_SHORT, LOCAL_SHORT, RECORD_SHORT
- Extended forms: ABSOLUTE, REGISTER, LOCAL, RECORD, DESCRIPTOR, PREINDEXED
- Special: ALT prefix (0xC8), post-increment modes, indirect addressing
CPU Register Set:
- PC (Program Counter), FLAGS
- I[4] (Index registers), A[4] (Address registers), E[4] (Extension registers)
- L (Level), B (Base), R (Return)
- Stack: TOS, LL, HL, THA
- Table registers: OTE1/2, CTE1/2, MTE1/2, TEMM1/2
Dependencies¶
Native Build¶
| Dependency | Required | Purpose | Installation |
|---|---|---|---|
| libcjson | Optional | JSON output support | apt install libcjson-dev (Debian/Ubuntu)pkg-config --modversion cjson |
| pthread | Yes (Unix) | Background execution thread | Built into libc on Linux/Unix |
| external/libdap | Optional | Debug Adapter Protocol server | Git submodule: git submodule update --init (also needs libcjson) |
| external/libsymbols | Optional | Symbol table support | Clone into external/libsymbols/ |
If libcjson is not found, the native build proceeds without JSON support. If libreadline is not found, the debugger will work without tab completion and command history.
WebAssembly Build¶
| Dependency | Required | Purpose | Installation |
|---|---|---|---|
| Emscripten SDK | Yes | WASM compilation | Get Emscripten |
| cJSON | Yes | JSON support | Auto-fetched via CMake FetchContent |
Platform Support¶
| Platform | Status | Notes |
|---|---|---|
| Linux | ✅ Full support | Tested on Ubuntu 20.04+ |
| Windows | ✅ Full support | MinGW (w64devkit or MSYS2) - see build.bat. MSVC is not tested. |
| WebAssembly | ✅ Full support | Emscripten-based, web debugger interface |
| macOS | ⚠️ Untested | POSIX, so it should build, but it never has been |
Windows notes: ~ in a path expands to your Documents folder (resolved
through the shell API, so folder redirection into OneDrive is handled), and the
console is switched to virtual-terminal input mode so function keys - including
F12 for the NDIX menu - reach the emulator.
Project Structure¶
nd500x/
├── src/
│ ├── ndlib/ # Logging and utilities
│ │ ├── ndlib.c # Core logging
│ │ ├── ndlib_aout.c # a.out binary loader
│ │ └── ndlib_symbols.c # Symbol table support
│ ├── disasm/ # Disassembly module
│ │ ├── nd500_disasm.c # JSON-based disassembly formatter
│ │ └── nd500_disasm.h # Disassembly API
│ ├── machine/ # Machine state and debug API
│ │ ├── machine.c # Memory, bus, run loop
│ │ ├── machine_loader.c
│ │ ├── debug_api.c # Unified debug interface
│ │ ├── breakpoints.c # Breakpoint management
│ │ └── io.c
│ ├── cpu/ # CPU core
│ │ ├── cpu.c # Register state, reset, step, traps
│ │ ├── cpu_instr.c # Instruction decoder, O(1) dispatch, addressing modes
│ │ ├── cpu_protos.h # CPU API and operand access helpers
│ │ ├── nd500_instructions.c # Pre-generated dispatch table (1,078 entries)
│ │ ├── nd500_instructions.h # Dispatch table declarations
│ │ └── instructions/ # Instruction implementations (241 files in 13 categories)
│ │ ├── ARITHMETIC/ # 37 arithmetic operations (add, sub, mul, div, etc.)
│ │ ├── MOVE/ # 56 data transfer instructions
│ │ ├── SYSTEM/ # 35 system control instructions
│ │ ├── CALL/ # Call/return instructions
│ │ ├── STRING/ # String manipulation operations
│ │ ├── BRANCH/ # Conditional/unconditional branches
│ │ ├── FLOAT_MATH/ # Floating-point math operations
│ │ ├── COMPARE/ # Comparison instructions
│ │ ├── BITFIELD/ # Bit manipulation operations
│ │ ├── LOGICAL/ # Logical operations (and, or, xor, etc.)
│ │ ├── SHIFT/ # Shift and rotate instructions
│ │ ├── CONTROL/ # Control flow operations
│ │ └── IO/ # I/O instructions
│ ├── debugger/ # Interactive debugger
│ │ ├── debugger.c # REPL implementation
│ │ └── dap_adapter.c # Debug Adapter Protocol
│ └── frontend/
│ ├── nd500x/ # Native entry point
│ │ └── nd500x.c # Main entry point for native builds
│ └── nd500wasm/ # WebAssembly entry point
│ ├── main.c # WASM C interface (21 exported functions)
│ ├── tests/ # Unit tests for WASM
│ └── web/ # Web debugger interface
│ ├── index.html # Main UI
│ ├── style.css # Styling
│ ├── debugger.js # Frontend logic
│ └── demo/
│ └── kernel # Demo ND-500 kernel binary
├── external/ # External dependencies (git submodules)
│ ├── libdap/ # Debug Adapter Protocol library (optional)
│ └── libsymbols/ # Symbol table support library (optional)
├── test/ # Test suite (37,298 instruction validation tests)
│ ├── nd500-conformance.json # Master test file with all test cases
│ └── test_conformance.c # Test runner with negative test support
├── build/ # Build output (created by CMake, not in git)
│ ├── bin/ # Executables (nd500x, nd500wasm.js/wasm)
│ └── lib/ # Compiled libraries
├── CMakeLists.txt # Main CMake configuration
├── Makefile # Convenience wrapper for build commands
├── README.md # This file
└── CLAUDE.md # AI assistant guidance for development
CMake Options¶
| Option | Default | Description |
|---|---|---|
BUILD_WASM |
OFF | Build WebAssembly target with Emscripten |
DEBUGGER_ENABLED |
ON | Enable debugger support (forced OFF for WASM) |
SKIP_LIBDAP |
OFF | Build without the DAP server even if external/libdap is present |
Example:
cmake -DBUILD_WASM=ON ..
cmake -DDEBUGGER_ENABLED=OFF ..
cmake -DSKIP_LIBDAP=ON .. # same as: make without-dap
Contributing¶
Contributions are welcome! Please follow these guidelines:
- Code Style: Follow existing C11 conventions, use snake_case for functions
- Build: Ensure both native and WASM builds succeed
- Testing: Test debugger commands and instruction decoding
- Documentation: Update README.md and CLAUDE.md for architectural changes
Development Workflow¶
# Make changes
vim src/cpu/cpu.c
# Build and test
make clean
make
make run
# Test WASM build
make wasm-clean
make wasm
License¶
MIT - see LICENSE. Every source file carries an
SPDX-License-Identifier: MIT line.
Exceptions, each stated in the file itself: src/frontend/nd500x/telnetserver.[ch]
and net_compat.[ch] came from the nd100x project and keep their original
GPL-2.0-or-later notice; include/nd500_desc.h is a verbatim copy from the
pcc-nd500 tree; everything under external/ and tools/ndix/userland/ has its
own licence. tools/mkptypes/ (copied from nd100x) is public domain, written by
Eric R. Smith.
Acknowledgments¶
- Norsk Data ND-500 architecture documentation
- Emscripten project for WebAssembly tooling
- cJSON library by DaveGamble
Support¶
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Status: Active Development | Version: 0.9.0 | Tests: 37,298 passing (100%)