Skip to content

Commit

Permalink
fix ZP inaccuracies
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvic-dev committed May 3, 2024
1 parent ff1ae03 commit 1571d94
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ uint8_t CPU::fetchByteWithMode(AddressingMode mode) {
case ZERO_PAGE:
return bus->read(fetchByte());
case X_ZERO_PAGE:
return bus->read(fetchByte() + x);
return bus->read((uint8_t)(fetchByte() + x));
case Y_ZERO_PAGE:
return bus->read(fetchByte() + y);
return bus->read((uint8_t)(fetchByte() + y));
case X_ZP_INDIRECT:
return bus->read(readWord(fetchByte() + x));
return bus->read(readWord((uint8_t)(fetchByte() + x), false));
case ZP_INDIRECT_Y:
return bus->read(readWord(fetchByte()) + y);
return bus->read(readWord(fetchByte(), false) + y);
default:
throw "invalid mode passed to fetchByteWithMode";
}
Expand All @@ -59,13 +59,13 @@ uint16_t CPU::fetchEffectiveModeValue(AddressingMode mode) {
case ZERO_PAGE:
return fetchByte();
case X_ZERO_PAGE:
return fetchByte() + x;
return (uint8_t)(fetchByte() + x);
case Y_ZERO_PAGE:
return fetchByte() + y;
return (uint8_t)(fetchByte() + y);
case X_ZP_INDIRECT:
return readWord(fetchByte() + x);
return readWord((uint8_t)(fetchByte() + x), false);
case ZP_INDIRECT_Y:
return readWord(fetchByte()) + y;
return readWord(fetchByte(), false) + y;
case RELATIVE: {
int8_t offset = fetchByte();
// PC now points at the next instruction, apply the offset to PC
Expand Down

0 comments on commit 1571d94

Please sign in to comment.