diff --git a/cpu.c b/cpu.c index d754c15..5bd114e 100644 --- a/cpu.c +++ b/cpu.c @@ -443,7 +443,12 @@ ldy(uint8_t arg) static void lsr(uint8_t arg) { -/* TODO: complete this */ + regs.status.carry = regs.a & 1; // bit 0 in carry + regs.a >>= 1; + regs.a &= ~(1 << 7); // bit 7 cleared + + STATUS_UPDATE_ZERO(regs.a); + STATUS_UPDATE_NEGATIVE(regs.a); } static void @@ -512,13 +517,29 @@ ply(uint8_t arg) static void rol(uint8_t arg) { -/* TODO: complete this */ + uint8_t tmp; + tmp = (regs.a & (1 << 7)) > 0; + + regs.a <<= 1; + regs.a |= regs.status.carry; + + regs.status.carry = tmp; + STATUS_UPDATE_ZERO(regs.a); + STATUS_UPDATE_NEGATIVE(regs.a); } static void ror(uint8_t arg) { -/* TODO: complete this */ + uint8_t tmp; + tmp = regs.a & 1; + + regs.a >>= 1; + regs.a |= regs.status.carry << 7; + + regs.status.carry = tmp; + STATUS_UPDATE_ZERO(regs.a); + STATUS_UPDATE_NEGATIVE(regs.a); } static void