Skip to content

ivan-pi/fc8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fc8

Fortran CHIP-8 interpreter

Building fc8

Prerequisites

The following tools and libraries are required:

  • Fortran 2008 compiler such as gfortran or ifx
  • C compiler
  • CMake v3.16 or higher
  • Xlib - the X window system protocol client library
  • (alternative, still beta-quality) SDL2

Build steps

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>

Using fc8

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:

CHIP-8 key binding

X-forwarding

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.

Examples

Some example ROMs can be bound in the cartridges/ directory. ROMS/cartridges can be loaded at the command line:

$ ./fc8 <cartridge>

Tests

To test the interpreter, I have used the ROM images found in the following third-party repositories (in this order of helpfulness):

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:

Graphics and keyboard input

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.

Writing and editing ROMs manually

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.

CHIP8 Assemblers

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:

Other resources

Explore

Acknowledgements

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