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.
This commit is contained in:
Vineet K 2024-06-16 17:11:51 +05:30
parent 745496ccd1
commit 1f6e3b054c

26
cpu.c
View File

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