aquova / chip8-book

An introduction to Chip-8 emulation using Rust

Home Page:https://aquova.net/chip8/chip8.pdf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modern 8XY6 and 8XYE not necessarily correct

MolotovCherry opened this issue · comments

It might be worth making a note in the book about instructions 8XY6 and 8XYE.

It turns out the these instruction's meaning somehow got changed with time. Since the idea about the implementation of these is so widespread these days, this leaves the emulator implementor with a dilemma, support the original way (for original ROMs), or support the new way?

Generally it's likely a good idea to support both ways, seeing as its possible one may run into older ROMs which rely on the original correct behavior.

https://web.archive.org/web/20170213223712/http://laurencescotford.co.uk/?p=266

Only the first five of these instructions were officially documented by RCA. 8XY6, 8XY7 and 8XYE are all undocumented. Unfortunately an erroneous assumption about 8XY6 and 8XYE, the two shift instructions, seems to have crept into Chip-8 lore at some point. Most recent documentation on Chip-8 suggests these instructions shift VX rather than VY. Some documents suggest that the correct format for them is 8X06 and 8X0E. However, when these instructions are run on the original Chip-8 interpreter, they will shift VY not VX! An instruction of the form 8X06 or 8X0E will not work as expected. The programmer would be expecting this to shift VX and store the result back in VX. What would actually happen is that V0 would be shifted and the result stored back in VX. This leaves the programmer of a contemporary interpreter with a bit of a dilemma. Do you make these instructions function as they would have done in the original interpreter or do you make them function in accordance with the erroneous assumption? Or do you offer both modes and a way to switch between them? This post documents the way the instructions worked in the original Chip-8 interpreter.

Edit: Also, here's a chip8 test suite. It revealed a few problems with the book's implementation, particularly this one
https://github.com/Timendus/chip8-test-suite