1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-06-11 05:29:33 +00:00

Use 9-bit rotation, not 8-bit

This commit is contained in:
Peter Evans 2018-02-15 19:32:01 -06:00
parent 067c0cea2f
commit 058b45e7d1

View File

@ -141,13 +141,19 @@ DEFINE_INST(rol)
MOS_CARRY_BIT();
SET_RESULT(oper << 1);
// Rotations are effectively _9-bit_. So we aren't rotating bit 7
// into bit 0; we're rotating bit 7 into the carry bit, and we're
// rotating the _previous value of the carry bit_ into bit 0.
if (cpu->P & MOS_CARRY) {
result |= 0x1;
}
if (oper & 0x80) {
carry = 1;
}
cpu->P &= ~MOS_CARRY;
if (carry) {
result |= 0x01;
cpu->P |= MOS_CARRY;
}
@ -169,13 +175,17 @@ DEFINE_INST(ror)
MOS_CARRY_BIT();
SET_RESULT(oper >> 1);
// See the code for ROL for my note on 9-bit rotation (vs. 8-bit).
if (cpu->P & MOS_CARRY) {
result |= 0x80;
}
if (oper & 0x01) {
carry = 1;
}
cpu->P &= ~MOS_CARRY;
if (carry) {
result |= 0x80;
cpu->P |= MOS_CARRY;
}