1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-27 05:49:24 +00:00

Mask the result so it's never more than a byte

This is because the eff_addr variable is a 16bit one, and adding addr +
X or addr + Y can possibly result in a 9-bit value, which is not what we
want. (You'd be pulling data from the stack instead of the zero page.)
This commit is contained in:
Peter Evans 2018-02-16 00:44:55 -06:00
parent e9164d9872
commit 0d1e949d13

View File

@ -260,7 +260,7 @@ DEFINE_ADDR(zpg)
DEFINE_ADDR(zpx) DEFINE_ADDR(zpx)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr + cpu->X); EFF_ADDR((addr + cpu->X) & 0xff);
return mos6502_get(cpu, eff_addr); return mos6502_get(cpu, eff_addr);
} }
@ -272,7 +272,7 @@ DEFINE_ADDR(zpx)
DEFINE_ADDR(zpy) DEFINE_ADDR(zpy)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr + cpu->Y); EFF_ADDR((addr + cpu->Y) & 0xff);
return mos6502_get(cpu, eff_addr); return mos6502_get(cpu, eff_addr);
} }