For other implementations, see https://github.com/lj-ditrapani/16-bit-computer-specification.
The processor instruction set architecture (ISA) can be found in ISA.md.
https://www.npmjs.com/package/ljd-16-bit-cpu
npm install --save ljd-16-bit-cpu
From browser:
<script type="module">
import { makeCpu, makeDebugCpu } from "/lib/ljd_16_bit_cpu.js"
// do stuff
</script>
From node.js:
import { makeCpu, makeDebugCpu } from 'ljd-16-bit-cpu'
// do stuff
Run a program
// programRom is a array of 16-bit integers with length <= 65,536
const cpuWithIoRam = makeCpu(programRom, dataRom)
const cpu = cpuWithIoRam.cpu
const ioRam = cpu.run(1000)
Step through a program
const cpuWithIoRam = makeDebugCpu(programRom, dataRom)
const cpu = cpuWithIoRam.cpu
cpu.step()
cpu.step()
// ...
Example program in hex
// This program adds the values in dataRom[0] and dataRom[1]
// then stores the result in ioRam[512]
// 27 + 73 = 100
// Address $FA00 is the beginning of screen RAM == ioRam[512]
const programRom = [
0x100A, // HBY 0x00 RA
0x200A, // LBY 0x00 RA
0x3A01, // LOD RA R1
0x201A, // LBY 0x01 RA
0x3A02, // LOD RA R2
0x5123, // ADD R1 R2 R3
0x1FAA, // HBY 0xFA RA
0x200A, // LBY 0x00 RA
0x4A30, // STR RA R3
0x0000 // END
]
const dataRom = [27, 73, 0]
const cpuWithIoRam = makeCpu(programRom, dataRom)
const cpu = cpuWithIoRam.cpu
const ioRam = cpu.run(1000)
console.log(ioRam[512]) // prints 100
https://lj-ditrapani.github.io/16-bit-cpu-ts/
Install node with https://github.com/nvm-sh/nvm.
nvm install # one-time install
nvm use # each time you enter the project directory
Install npm packages.
npm install
npm run all
This produces a single ljd_16_bit_cpu.js esm module for both node and browser environments.
# Run the tests with `npm run all` or
npm test
# This will generate the test coverage report
# Then open the test coverage report
firefox coverage/lcov-report/index.html
Run manual test in browser; prints 100 to dev console.
npm run browser-test
Then open localhost:8000/manual-test.html in your browser. Open the developer console to see the 100.
firefox localhost:8000/manual-test.html
Run manual test on node; prints 100.
node manual-test.js
npm run doc
firefox docs/index.html &
npm run ncu
rm -fr lib
npm run all
npm version patch/minor/major
npm login
npm publish
Author: Lyall Jonathan Di Trapani
Generated using TypeDoc