|
11 months ago | |
---|---|---|
src | 11 months ago | |
Cargo.lock | 11 months ago | |
Cargo.toml | 11 months ago | |
README.md | 11 months ago | |
atomic_arrray.txt | 12 months ago | |
generate_video_array.py | 12 months ago |
README.md
Hack Platform Simulator
Introduction
Noam Nisan and Shimon Schocken introduced the “Hack” platform in their 2005 textbook “The Elements of Computing Systems” published by MIT press (https://www.nand2tetris.org/). The book takes students on a voyage of discovery by guiding them through building a complete computer platform, starting by using NAND gates to build more complex chips eventually culminating in a CPU and a complete software stack including an assembler, virtual machine translator, high-level language compiler and finally an operating system that can run programs such as Tetris. This process is informally known as Nand2Tetris and the book consists of 13 chapters, each chapter providing the necessary knowledge and then setting a project which, once implemented, acts as a layer in the computer system.
Hack is a simple 16-bit Von Neumann architecture that can be built from elementary NAND gates and Flip-Flops. The instruction set is extremely simple with a focus on hardware simplicity. Even basic operations like multiply and divide do not have hardware implementations and rely on software procedures. Programs are supplied to the computer in the form of replaceable ROM chips, similar to some cartridge-based games consoles. Most memory management is performed at the VM level and the program memory is read-only which leads to a simple single-tasking operating system that acts more like a standard library for the high-level language. Despite this the computer is powerful and building it is an extremely informative journey.
You can see my implementation of the Hack platform here: https://git.jbm.fyi/jbm/Nand2Tetris
What is this?
This is a simulator for the Hack plaform developed in rust capable of running Hack binaries. The goal is to slowly add modern CPU optimisations to the simulator and evaluate the performance effects of these optimisations. There will be a full write up on my website at https://portfolio.jbm.fyi/ after the project is complete.
Usage
cargo run --release -- [path to program] [mode: 16/32] [target clock speed (0 for unlimited)] [fps] [scale factor]
For example:
cargo run --release -- ../programs/bin/big/Pong.hack 32 0 60 2
Of course, you can replace cargo run --release --
with a compiled binary. Note that only around 10% performance is acheived when compiling without the release flag. To build this binary, you must have the relevant SDL dev package installed for your environment.
You can find a number of binaries (along with source code and build tools) for the platform here: https://git.jbm.fyi/jbm/hack_toolchain