Advertisements
SuperCHIP emulator running Space Fight 2091

How to make a SuperCHIP emulator

I recently wrote a few articles about a small weekend project I’ve been working on. My goal was to create a Chip8 emulator. It was my first emulator ever and I got so excited by the result that I decided to write a series of tutorials hoping to get people inspired. But then I went back to the code and I upgraded it to a SuperCHIP emulator. That’s right, it is serious business now.
SuperCHIP emulator running Space Fight 2091. Get the full source code on GitHub

SuperCHIP is an extension on the original Chip8 design, it provides a few nice improvements such as a new “high resolution” 128×64 video mode, scrolling the screen and showing bigger sprites. At first I didn’t plan this, but then I had a quick look at the documentation and decided that it was actually a very tiny effort to implement the new features. So I did it. Once more I was very satisfied by the result.

Super AstroDodge
Single Dragon

I decided to keep the original Chip8 emulator untouched because my tutorial uses portions of the code all the time. Instead I forked the Chip8 emulator, renamed it SuperCHIP emulator and started working on adding the SuperCHIP features.

Chip8 vs SuperCHIP

Here is a list of the cool new features that SuperCHIP provides

  • High resolution 128×64 pixels. This mode must be explicitly enabled by the programmer using the opcode HIGH. It is possible to go back to low resolution with the opcode LOW at any time.
  • New SCD and SCU opcodes to scroll the screen up and down. These opcodes accept an argument, which is the number of lines to scroll. This number is divided by two if high resolution mode is not enabled.
  • New SCL and SCR opcodes to scroll the screen left and right. These opcodes have no argument, they always scroll the screen by 4 pixels in high resolution mode and by 2 pixels in low resolution mode.
  • Bigger sprites of 8×16 pixels. The programmer can draw an 8×16 sprite using the same old DRW opcode in high resolution mode and specifying an height of zero as argument.
  • The interpreter provides 8×10 pixels font sprites for digits in addition to the font sprites already provided by a Chip8 interpreter. A new opcode loads the address of an 8×10 font sprite inside register I.
  • A new EXIT opcode to halt the execution.
  • New opcodes LD R, Vx and LD Vx, R to save and restore value registers from 0 to 7 inside the RPL flags. RPL was a programming language for HP calculators, these two opcodes effectively enable communication with the real machine that is running the interpreter.

Quirks and Pitfalls

Implementing the new features took a couple of hours including testing. However I found out something more about Chip8 and SuperCHIP, something annoying. At least two opcodes have been historically implemented differently by many interpreters. This caused some rom to run fine on an implementation and to do weird stuff on another. At first I thought I still had bugs in my emulator but then I found this page from a guy with the same issues. Unfortunately these two opcodes must have a slightly different implementation depending on the rom:

  • LD [I], Vx and LD Vx, [I] read and write value registers from 0 to x at the memory address pointed to by register I. Some roms assume that the I pointer is incremented by x after the operation while some other roms do not.
  • SHR Vx {, Vy} and SHL Vx {, Vy} some of the documentation I found about this opcodes mentions that register Vy is shifted left or right and the result is then stored in register Vx. Some other documentation specifies that register Vx is shifted instead. There seem to be no universal agreement on how this should work.

That’s all folks

So this is the SuperCHIP emulator in a nutshell. I hope you liked this, if you followed my tutorial on Chip8 reading this should be enough to step up your game and go SuperCHIP. If you face issues remember that the code is there for you 🙂

Unique opportunity! Help a fellow grow his blog!
Hi there! If you’ve read this far maybe you think this was useful, or fun, or I don’t know what but for some reason You Got Here! Great! Please consider sharing this post with your network, I am trying to get The Code Butchery to grow so I can provide more content like this, will you help me in my journey? Thank you!
Series Navigation<< Write a Chip8 retro gaming emulator in one day. The CPU. And it’s done.
Advertisements
Share this

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.