kurtjd / jaxe

A fully-featured, cross platform XO-CHIP/S-CHIP/CHIP-8 emulator written in C and SDL.
MIT License
30 stars 5 forks source link
c chip-8 chip-8-emulator chip8 emulator s-chip sdl xo-chip

JAXE (Just Another XO-CHIP/CHIP-8 Emulator)

Brix Space Invaders (In Debug Mode)
Black Rainbow DVN8
Super Neat Boy Chicken Scratch

CHIP-8 was a virtual machine/programming language developed by Joseph Weisbecker for the COSMAC VIP in the 1970s. It was designed with 35 opcodes and resembles assembly language, but was made for the easier development of video games on the VIP.

Today, it is a popular target to be emulated because of its simplicity and charm.

Features

Technical Info

The original CHIP-8 virtual machine was designed with the following specs:

Due to the way CHIP-8 was designed, the "flicker" that happens when sprites are drawn is normal. Games developed for it also rarely made any attempt to cap their frame rate due to the slow hardware of the time hence the need to artificially slow the CPU down on modern emulators.

In the early 90s, Andreas Gustafsson created a port for the HP48 calculator which was eventually superseded by S-CHIP 1.0/1.1 created by Erik Bryntse. The S-CHIP added several features as well as accidentally (or intentionally?) modifying the behavior of several original opcodes:

With time, it seems the S-CHIP became more popular and many programs were written to work with its various quirks. Thus, JAXE defaults to original S-CHIP design however many of its quirks can be toggled for improved compatibility using the flags in the Options section below.

However, recently John Earnest designed the XO-CHIP extension allowing CHIP-8 programs to take advantage of modern hardware to an extent. This extension adds several more instructions and features including:

JAXE currently supports all of these extensions.

It should also be noted that JAXE stores its fonts in memory starting at address 0x0000 followed immediately by large fonts and finally immediately by the stack. Therefore the stack pointer initially points to address 0x00F0.

TODO

Requirements

Build Procedures

Linux/Windows (MinGW)

mkdir build && cd build
cmake -B . -DCMAKE_BUILD_TYPE=Release ..
make

Windows (non-MinGW)

Unknown at this time. Currently the code uses the POSIX getopt() function to handle command-line arguments. To build without MinGW, remove #define ALLOW_GETOPTS from the top of main.c which will unfortunately remove command-line arguments until I handle them in a portable way.

Run

Linux

./jaxe [options] <path-to-rom/dump-file>
./test (for unit tests)

Windows

If built with MinGW, command line options are available:
jaxe.exe [options] <path-to-rom/dump-file>

Otherwise:
jaxe.exe <path-to-rom/dump-file>
test.exe (for unit tests)

Options

-l Enable legacy mode (for running original CHIP-8 ROMs)
-x Enable XO-CHIP mode
-d Enable debug mode
-m Load dump file instead of ROM
-p Set program start address (in hex)
-c Set CPU frequency (in Hz, value of 0 means uncapped)
-t Set timer frequency (in Hz, value of 0 means uncapped)
-r Set screen refresh frequency (in Hz, value of 0 means uncapped)
-s Set display scale factor
-b Set background color (in hex)
-f Set plane1 color (in hex)
-k Set plane2 color (in hex)
-n Set overlap color (in hex)

Also includes flags for disabling specific S-CHIP "quirks" (which are all enabled by default):

-0 Disable uninitialized RAM
-1 Disable 8xy6/8xyE bug
-2 Disable Fx55/Fx65 bug
-3 Disable Bnnn bug
-4 Disable ban on big sprites being drawn in LO-RES mode
-5 Disable display state remaining the same when 00FE/00FF execute (display is cleared with this disabled)
-6 Disable sprite clipping
-7 Disable collision enumeration
-8 Disable collision check with bottom of screen
-9 Disable undefined VF after logical OR, AND, XOR (VF is set to 0 with this disabled)

Controls

Keyboard (This maps to the key layouts below)

1 2 3 4
Q W E R
A S D F
Z X C V

COSMAC VIP Keypad

1 2 3 C
4 5 6 D
7 8 9 E
A 0 B F

HP48 Keypad

7 8 9 /
4 5 6 *
1 2 3 -
0 . _ +

Other Controls

Key Action
SPACE Pause/Unpause
UP Step Forward (DBG Mode Only)
DOWN Step Back (DBG Mode Only)
RIGHT Increase CPU Speed
LEFT Decrease CPU Speed
ENTER Save/Create Dump File
BACKSPACE Cycle Color Themes
ESC Reset Emulator

Troubleshooting

Libretro port

Libretro port is intended to run under Retroarch on a wide variety of platforms. Compilation:

make -f Makefile.libretro
make -f Makefile.libretro platform=PLATFORM
cd jni/
ndk-build

Running from command line:


retroarch -L jaxe_libretro.so  roms/chip8archive/br8kout.ch8

I hope to add it to buildbot and official distribution shortly

Default key mapping:

This is preliminary and subject to change.

Differences and notes compared to standalone version:

TODOs:

Contributing

Anyone is welcome to contribute! I will try to review pull requests as quickly as possible.

License

JAXE is licensed under the MIT license so you are free to do almost whatever you please with this code (see LICENSE file).

ROMs

References

Acknowledgments