From dbb952a52b1b7168b4d1e98e9819d632ad16e087 Mon Sep 17 00:00:00 2001 From: vin Date: Mon, 10 Jun 2024 14:27:53 +0530 Subject: [PATCH] add lsr, rol, ror --- cpu.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) 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