add lsr, rol, ror

This commit is contained in:
Vineet K 2024-06-10 14:27:53 +05:30
parent ebdf50cdf3
commit dbb952a52b

27
cpu.c
View File

@ -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