I am watching a Javascript emulator from NES to try to understand how this works.
In this line :
addr = this.load(opaddr+2);
The operation code is increased by two. However, the documentation (see Appendix E) I read:
When accessing the zero page, one operand is used, which serves as a pointer to the address on the zero page (0000- $ 00FF), where the data to be used can be found. Using zero page addressing, only one byte is needed for the operand, so the instruction is shorter and therefore faster than with addressing modes that accept two operands. An example of a zero page instruction is AND $ 12.
So, if the argument of the operand is only one byte, should it not appear immediately after it and be + 1 instead of + 2? Why is +2?
This is how I think it works, which may be wrong. Suppose our memory looks like this:
------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | <- index ------------------------- | a | b | c | d | e | f | <- memory ------------------------- ^ \ PC
and our PC is 0 , pointing to a . For this loop, we say that the operation code is:
var pc= 0;
So the first operand should not be the next slot, i.e. b ?
var first_operand = memory[pc + 1];
source share