Strata ยท the computer

Strata

A whole computer in one HTML file.

The program on the screen is C source code. A C compiler written from scratch turns it into RISC-V machine code, and a CPU emulator written from scratch executes it, one instruction at a time. No server, no WebAssembly, no libraries. Change the code and press Run.

Ctrl Enter runs
Ready.
Click the screen to use the keyboard
Click the screen, then arrows / WASD move · Z or Space acts
Source 
Compiler 
Assembler 
CPU 
Screen 

The compiler

Lexer, preprocessor, recursive-descent parser, type checker and a RISC-V code generator. Structs by value, function pointers, floats, switch, macros, a register allocator. Checked against GCC: the same programs must print the same output.

The assembler

Turns the compiler's text output into real RV32IMF machine code, with labels, pseudo-instructions and branch relaxation. Its encodings match LLVM's assembler bit for bit.

The CPU

A 32-bit RISC-V core with integer multiply/divide and single-precision floats, 16 MB of RAM, a 320×240 framebuffer, a four-voice sound chip and six system calls. It also runs binaries built by Clang.

The programs

A ray-cast maze game, a path tracer, a z-buffered 3D rasteriser, demo effects, a falling-sand toy and a sequencer. Each is one C file you can read and edit in the Source tab.