From 1f6e3b054cd7a35c5eb8d908525a261ea83d44e7 Mon Sep 17 00:00:00 2001 From: vin Date: Sun, 16 Jun 2024 17:11:51 +0530 Subject: [PATCH] replace bit comparisons with 0 from greater than to not equal They're both the same and the compiler might have already optimized it away. It also conveys the message better in my opinion. --- cpu.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cpu.c b/cpu.c index 0fe6cbd..61b835c 100644 --- a/cpu.c +++ b/cpu.c @@ -8,7 +8,7 @@ #define STATUS_UPDATE_ZERO(r) \ (regs.status.zero = r == 0) #define STATUS_UPDATE_NEGATIVE(r) \ - (regs.status.negative = ((r & (1 << 7)) > 0)) + (regs.status.negative = ((r & (1 << 7)) != 0)) #define MEMORY_MIRROR(addr) \ if (addr < 0x2000) \ @@ -197,7 +197,7 @@ adc(uint8_t arg) regs.status.carry = sum > 0xFF; /* overflow flag formula: https://stackoverflow.com/a/29224684 */ - regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) > 0; + regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) != 0; STATUS_UPDATE_ZERO(regs.a); STATUS_UPDATE_NEGATIVE(regs.a); } @@ -262,7 +262,7 @@ static void bit(uint8_t arg) { regs.status.zero = (regs.a & arg) == 0; - regs.status.overflow = (arg & (1 << 6)) > 0; + regs.status.overflow = (arg & (1 << 6)) != 0; STATUS_UPDATE_NEGATIVE(arg); } @@ -557,21 +557,21 @@ plp(void) status = PULL(); - regs.status.carry = (status & (1 << 7)) > 0; - regs.status.zero = (status & (1 << 6)) > 0; - regs.status.interrupt_disable = (status & (1 << 5)) > 0; - regs.status.decimal_mode = (status & (1 << 4)) > 0; - regs.status.brk = (status & (1 << 3)) > 0; - regs.status.unused = (status & (1 << 2)) > 0; - regs.status.overflow = (status & (1 << 1)) > 0; - regs.status.negative = (status & 1) > 0; + regs.status.carry = (status & (1 << 7)) != 0; + regs.status.zero = (status & (1 << 6)) != 0; + regs.status.interrupt_disable = (status & (1 << 5)) != 0; + regs.status.decimal_mode = (status & (1 << 4)) != 0; + regs.status.brk = (status & (1 << 3)) != 0; + regs.status.unused = (status & (1 << 2)) != 0; + regs.status.overflow = (status & (1 << 1)) != 0; + regs.status.negative = (status & 1) != 0; } static void rol_acc(void) { uint8_t carry; - carry = (regs.a & (1 << 7)) > 0; + carry = (regs.a & (1 << 7)) != 0; regs.a <<= 1; regs.a |= regs.status.carry; @@ -585,7 +585,7 @@ static void rol(uint16_t mem) { uint8_t carry, tmp; - carry = (peek(mem) & (1 << 7)) > 0; + carry = (peek(mem) & (1 << 7)) != 0; tmp = (peek(mem) << 1) | regs.status.carry; memwrite(mem, tmp);