OneLoneCoder/olcNES

Possible bug at the indirect zeropage with x register offset

i3abghany opened this issue · 3 comments

Shouldn't we check whether the offset has made the address jump to another page or not? just like the Y register indirect zeropage offset addressing mode?

std::uint8_t olc6502::IZX()
{
	std::uint16_t addr = this->read(this->PCReg);
	++this->pc;

	std::uint16_t lo = this->read(addr & 0x00FF);
	std::uint16_t hi = this->read((addr + 1) & 0x00FF);

	this->addr_abs = (hi << 8) | lo;
	this->addr_abs += this->x;

	if (this->addr_abs & 0xFF00 != hi << 8)
	{
		return 1;
	}
	return 0;
}

p.s.: I know the two halves are taken from the memory in a different way in the original source code but I still think that the pagination would cause a problem.

No we only check in the Y register. I can't tell you why they're different but the datasheet tells you what's expected and the address jump is only on the Y register.

If you're calculating an address based on the zero page (like with the +X), it has to stay on the zero page (no page crossing). Same rule applies to the ZP0, ZPX and ZPY modes. But if you read an address from there (like with the +Y), that address address is no longer limited to the zero page and page crossing could happen.

Also, don't confuse (addr,X) and (addr),Y. The first one read an address from addr+x and then read or write data at that new location while the second read an adress from addr then add Y to that new address and finally read or write data at that final location. What you've created with your code is (addr),X which doesn't exist on the 6502.