XChip-8
This is a simple virtual machine for Chip-8 machine language. It runs on most *nix systems with X11. In fact, I compiled it on GNU/Linux (various flavors), SunOS 5.9, FreeBSD 6.2, and even Cygwin. I had to "fix" the Makefile to work for all systems other than GNU/Linux and SunOS; it seems like the "make" utility is broken in FreeBSD (it doesn't seem to recognize the "$<" pseudo-variable correctly), and apparently libraries must be at the end of the compilation command line in Cygwin (something to do with the resolution of external symbols).
I'm developing this program only in my free time, so don't expect it to be perfect.
Features
- Motion blur. This makes the graphics look "smoother" and more natural for fast-moving objects.
- Resizable window. The window maintains its aspect ratio of 2:1 (width:height) when it's resized.
- Low processor usage. The virtual machine shows hardly any CPU usage in "top" (process monitor in *nix) on a modern-ish computer. (On the other hand, it consumes a large amount of CPU time on a 200MHz computer.)
- Free software. I licensed this program under the GNU General Public License for anyone to inspect the source and possibly improve it.
News
- 2006-12-20: Updated XChip-8
- Cleaned up timing code
- Frame rate and instruction rate now are settable on the command line
- Added stub support for sound
- Titlebar says "[paused]" when the VM is paused
- 2006-11-04: Updated XChip-8!
- Reduced network usage.
- Sets the standard X Window Manager properties, such as the application class and name. This shows up in the KDE or GNOME task bar when xchip8 is run multiple times.
- Cleaned up the screen refreshing code. Screen re-draws only where it receives an Expose event.
- Clears memory when the virtual machine is reset.
- Compiles cleanly on at least GNU/Linux and SunOS 5.9. Also compiles in Cygwin if the "-lX11" is moved to the end of the linking phase in the Makefile.
Screenshots
Here are some screenshots of XChip-8:





Compiling and running
In order to run the program, you must first compile it. First extract the archive, then at a command prompt, type 'make'. If it compiles without errors, run it as './xchip8 program', where program is the filename of the Chip-8 program.
You can find many Chip-8 programs on-line. Some places to look are The CHIP-8 Emulator HomePage and http://www.pdc.kth.se/~lfo/chip8/CHIP8/GAMES/
Keys
The Chip-8 uses a 4x4 keypad, so I chose to use the following keys on a modern keyboard (this is subject to change in future versions):
| 7 | 8 | 9 | 0 |
| u | i | o | p |
| j | k | l | ; |
| m | , | . | / |
I also mapped the following keys to extra functions:
| Key | Function |
|---|---|
| q | Quit |
| r | Reset virtual machine |
| Space | Pause the virtual machine |
| Tab | Take a screenshot in the current directory |
Both upper- and lower-case letters work for all of the keys.
Limitations
Here are some limitations of the current version of XChip-8:
- It does not play any sound. Basic support is being implemented, though.
- Only the basic Chip-8 instructions have been tested thoroughly; the Super Chip-8 instructions haven't been tested completely, and some Super Chip-8 games don't run properly because of this.
Sprite wrap-around: I can't find any definitive answers on whether sprites actually wrap around the screen or not. Some games (e.g., Blitz) don't work well with wrap-around, while others (e.g., Syzygy) don't work well without wrap-around, or at least they doesn't seem to work how I think they ought to work.It seems that horizontal wrap-around and no vertical wrap-around works.
To Do
Here's a list of items for improving XChip-8:
Move the instruction decoding/execution code from the main function to its own function.- Improve the key-handling code to reduce polling of the X server. I'm fairly new to X programming, so I need to read more on how it works.
- Add sound, using at least XBell.
- Add command-line switches and/or configuration file to control
framerate, execution speed,key maps, debugging/disassembling, etc. - Test the Super Chip-8 instructions more thoroughly.
- Split the growing xchip8.c file into separate module files.
Download
Here is the complete source code in one download: xchip8.tgz.
License
XChip-8 is Copyright 2006 Christopher Williams.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.