Fortran CHIP-8 interpreter
The following tools and libraries are required:
- Fortran 2008 compiler such as
gfortran
orifx
- C compiler
- CMake v3.16 or higher
- Xlib - the X window system protocol client library
- (alternative, still beta-quality) SDL2
Clone the repository and build using CMake
$ git clone
$ mkdir build && cd build
$ cmake .. -DFC8_KEYBOARD=qwertz
$ make
The keyboard binding is fixed at compile time. You can select between:
qwerty
(default)qwertz
azerty
If the build was succesful, you should now be able to play a CHIP-8 game using:
$ ./fc8 <path/to/cartridge>
The full set of command-line options is:
Usage: fc8 [-h] [-s] [-zoom=Z] [--config=FILE] <path-to-ch8>
Fortran CHIP-8 interpreter
required arguments:
<path-to-ch8> a CHIP8 ROM file
options:
-h, --help show this help text and exit
-v, --version display version and exit
-s, --silent silent mode (disable audio)
--zoom=Z zoom percentage, 30 <= Z <= 200
--display=:N server display number; the default is 0
--config=FILE configuration file: a Fortran namelist
The interpreter display responds to the following keys
- Escape: Quit fc8
- 0: Reload ROM file ("replay")
The CHIP-8 keypad is bound to conventional keyboards as follows:
When the X11 version of fc8 was built, you can run it on a remote machine using X-forwarding. To do so you must have a running X-server (e.g. Xming on Windows, XQuartz on Mac). After logging in with
$ ssh -Y <userID>@<destination>
you should be able to run fc8 remotely.
Some example ROMs can be bound in the cartridges/
directory. ROMS/cartridges can be loaded at the command line:
$ ./fc8 <cartridge>
To test the interpreter, I have used the ROM images found in the following third-party repositories (in this order of helpfulness):
- https://github.com/Timendus/chip8-test-suite
- https://github.com/corax89/chip8-test-rom
- https://github.com/mattmikolay/chip-8
- https://github.com/Skosulor/c8int
It's often insightful to compare results with interpreters of others. Here are just a few:
(Note that many interpreters found on the internet are incomplete or misinterpret certain opcodes. In some cases, also the ROMs are broken or rely on implementation quirks.)
Larger collection of games and other demos can be found in:
- https://github.com/dmatlack/chip8
- https://johnearnest.github.io/chip8Archive/
- http://pong-story.com/chip8/
- SDL and fortran-sdl2
- GLUT/OpenGL
- GTK and gtk-fortran
- X11 or XCB
- Wayland
- Win32 (Windows)
- AppKit (MacOS)
- EGGX/ProCALL (no support for key-release detection)
One of my aims in this project was to investigate design patterns. One of the typical design problems in game development (or graphical programs in general) is how to support different graphical engines on different platforms.
The easy solution is to pick a graphics framework with widespread platform support. This way all of the platform specific issues are pushed down into the graphical layer.
Obviously, the requirements of a black and white, 2D game view are low compared to more realistic programs, however the designs patterns still apply.
For a true experience you can write the games by hand in pseudo-assembly,
and compile them to hex manually. You can use a hex editor such as hexyl
or hexedit
to save and edit your CHIP-8 programs.
The hexdump
tool can be used to quickly inspect a cartridge (watch out as different tools might display the byte-order differently). Alternatively, HexEd.it client-side JavaScript based hex editor is a more powerful tool which runs in the browser.
A far better developer experience is to use a high-level assembler. The most famous one today is Octo, which also includes a disassembler and emulator, as well as a sprite editor. A second alternative is Dorito.
Personally, I have found the customasm
tool working well too. Examples of CHIP8 programs written in a custom assembly language can be found in the asm/
folder of this repository.
Other assemblers:
- How to write an emulator (CHIP-8 interpreter) | Laurence Muller
- Introduction to CHIP-8 | Emulator 101
- CHIP-8 Technical Reference
- Emulating the Chip8 system | codeslinger.co.uk
- Chip-8 on the COSMAC VIP: Keyboard Input | Laurence Scotford
- CHIP-8 Reference | Gulrak's CHIP8 Cave
- Guide to making a CHIP-8 emulator | Tobias V. Langhoff
- How are held-down keys handled in CHIP-8? | Retrocomputing
- BUILDING A CHIP-8 EMULATOR [C++] | Austin Morlan
Special thanks goes to:
- @vmagnin, for supportive discussions, and testing of the build system and keyboard bindings on various platforms
- @interkosmos, for supportive discussions, code suggestions and educational Fortran content