diff options
author | vin <git@vineetk.net> | 2024-06-16 17:11:51 +0530 |
---|---|---|
committer | vin <git@vineetk.net> | 2024-06-16 17:11:51 +0530 |
commit | 1f6e3b054cd7a35c5eb8d908525a261ea83d44e7 (patch) | |
tree | f5f806f0a3c6e8ab5cd1305efb927558911ddaab /cpu.c | |
parent | 745496ccd1a4483cc0955ec0c34acd800991cff3 (diff) |
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.
Diffstat (limited to 'cpu.c')
-rw-r--r-- | cpu.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -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); |