Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increment I in chip-8 opcode FX65

Tags:

While building a chip-8 emulator, I ran into the problem where the 2 main sources of chip-8 information seem to differ which has implications for the whole chip-8 interpreter.

On the one side we have wikipedia, which under the opcode FX65 tells us that

"Fills V0 to VX (including VX) with values from memory starting at address I. I is increased by 1 for each value written."

where "I is increased by 1 for each value written." is the important part.

Following this results in the following code:

for(int i = 0; i <= ((opcode & 0x0F00) >> 8); ++i) {
    V[i] = memory[I];
    ++I;
}

on the other hand we have the chip-8 reference by cowgod, a reference almost every tutorial links to, which tells us the following

"The interpreter reads values from memory starting at location I into registers V0 through Vx."

Applying this logic results in the following code (this is also the implementation most chip-8 implementations use):

for(int i = 0; i <= ((opcode & 0x0F00) >> 8); ++i) {
    V[i] = memory[I + i];
}

The main difference between these two is that I is either incremented or not. Since I is the register index of the emulator, it is quite important for the program to work correctly.

What I want to know is which implementation of this opcode is correct.

like image 405
duck Avatar asked Jul 04 '18 18:07

duck


1 Answers

There doesn't seem to be a definitive answer, as there doesn't seem to be a definitive reference.

This reference seems to have the same problem with the same ambiguity

This (contemporary) reference (page 113), however, says "I = I + X + 1". Authorship is by the inventor, Joseph Weisbecker - I guess he will have known.

like image 188
tofro Avatar answered Sep 28 '22 17:09

tofro