4

The CHIP-8 instructions SAVE Vx (Fx55) and RESTORE Vx (Fx65) are originally specified to increment the pointer register I as each register is saved/loaded, so by the end of the instruction, the value of I is incremented by x + 1. However, lots of subsequent emulators didn't implement this behavior correctly (leaving I unchanged by these operations), and I have found at least one game (David Winter's HIDDEN) that outright breaks with a spec-conformant implementation: tiles get repeated across the board.

It is tempting to sweep this question under the rug for my CHIP-8 implementation, and just not change the I register in SAVE / RESTORE. But there are dozens of CHIP-8 games around. Does any of them depend on the correct behavior of SAVE / RESTORE and break if I is not updated?

1 Answer 1

4

But there are dozens of CHIP-8 games around.

By my count so far: 456.

Does any of them depend on the correct behavior of SAVE / RESTORE and break if I is not updated?

Yes, there are CHIP-8 games that will break if Fx55/Fx65 do not increment the index variable I.

Here's an excerpt from the source code listing to the game "5 Row Mastermind" by Robert Lindley, as printed in VIPER magazine, volume 1, issue 7, page 22, from February 1979 (memory addresses 0x2880x28E):

5 Row Mastermind, memory locations 0x288–0x28E

As you can see, the program first loads five bytes from memory (the player's "answer" to the Mastermind puzzle), then immediately stores those bytes in the five memory addresses following the first ones (as a "working copy").

Obviously, if I wasn't incremented between those two instructions, it would instead "overwrite" the player's answer with itself (a no-op), and the working copy would not be what the game would later expect.

However, lots of subsequent emulators didn't implement this behavior correctly (leaving I unchanged by these operations)

A short history lesson to explain how this schism occured: CHIP-8 faded into obscurity after 1983 (when the PC became the dominant platform, and computers rarely had hexadecimal keypads anymore and anyone could write BASIC easily). In 1990 it resurfaced on the HP48 graphing calculators, as CHIP48 and later the extended SUPER-CHIP. These new implementations introduced the Fx55/Fx65 incompatibility (among others); CHIP48 incremented I, but erroneously (it incremented it one time less than the COSMAC VIP, as it wasn't incremented on the final iteration), while SUPER-CHIP didn't increment it at all. You can read a detailed disassembly and analysis of that code here.

Since the old COSMAC VIP CHIP-8 interpreter and its games were, at that point in the Internet's nascent history, lost to time temporarily (found only in physical newsletters and on tape cassettes that hadn't been digitized in a modern manner), the SUPER-CHIP behavior became dominant. David Winter ported it to DOS, and it spread from there.

It is tempting to sweep this question under the rug for my CHIP-8 implementation, and just not change the I register in SAVE / RESTORE.

That sounds like a reasonable default behavior. The answer to a slightly rephrased version of your question, "Do any of the games that are readily available online break if I doesn't increment?", the answer is "probably not". Most games available today use the "modern" behavior, and most games that are made today (for Octojam each October, for example) are made to not depend on either behavior (by not relying on the value of I after such an operation) so they can run in as many interpreters as possible.

However, the best course of action is probably to allow this "quirk" (as the inconsistencies between CHIP-8 specifications are often called) to be configured by the user. Use the modern behavior as default, but put a toggle somewhere, so old games are playable as well. Many modern "emulators" (interpreters) do this, such as Octo.

3
  • 1
    So, 38 dozens. Or did you mean 456 dozens?
    – ninjalj
    Jun 28, 2020 at 10:19
  • 1
    @ninjalj 38 dozen, yeah. It wasn't a correction, but a clarification. There are a lot more CHIP-8 programs than people usually think based on what's been uploaded to the internet.
    – tobiasvl
    Jun 28, 2020 at 11:19
  • I wasn't aware of OctoJam and the huge number of new CHIP-8 games. That is very interesting, thanks!
    – Cactus
    Jun 29, 2020 at 1:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .