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 @@ | |||
| 8 | #define STATUS_UPDATE_ZERO(r) \ | 8 | #define STATUS_UPDATE_ZERO(r) \ |
| 9 | (regs.status.zero = r == 0) | 9 | (regs.status.zero = r == 0) |
| 10 | #define STATUS_UPDATE_NEGATIVE(r) \ | 10 | #define STATUS_UPDATE_NEGATIVE(r) \ |
| 11 | (regs.status.negative = ((r & (1 << 7)) > 0)) | 11 | (regs.status.negative = ((r & (1 << 7)) != 0)) |
| 12 | 12 | ||
| 13 | #define MEMORY_MIRROR(addr) \ | 13 | #define MEMORY_MIRROR(addr) \ |
| 14 | if (addr < 0x2000) \ | 14 | if (addr < 0x2000) \ |
| @@ -197,7 +197,7 @@ adc(uint8_t arg) | |||
| 197 | 197 | ||
| 198 | regs.status.carry = sum > 0xFF; | 198 | regs.status.carry = sum > 0xFF; |
| 199 | /* overflow flag formula: https://stackoverflow.com/a/29224684 */ | 199 | /* overflow flag formula: https://stackoverflow.com/a/29224684 */ |
| 200 | regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) > 0; | 200 | regs.status.overflow = (~(regs.a ^ arg) & (regs.a ^ sum) & 0x80) != 0; |
| 201 | STATUS_UPDATE_ZERO(regs.a); | 201 | STATUS_UPDATE_ZERO(regs.a); |
| 202 | STATUS_UPDATE_NEGATIVE(regs.a); | 202 | STATUS_UPDATE_NEGATIVE(regs.a); |
| 203 | } | 203 | } |
| @@ -262,7 +262,7 @@ static void | |||
| 262 | bit(uint8_t arg) | 262 | bit(uint8_t arg) |
| 263 | { | 263 | { |
| 264 | regs.status.zero = (regs.a & arg) == 0; | 264 | regs.status.zero = (regs.a & arg) == 0; |
| 265 | regs.status.overflow = (arg & (1 << 6)) > 0; | 265 | regs.status.overflow = (arg & (1 << 6)) != 0; |
| 266 | STATUS_UPDATE_NEGATIVE(arg); | 266 | STATUS_UPDATE_NEGATIVE(arg); |
| 267 | } | 267 | } |
| 268 | 268 | ||
| @@ -557,21 +557,21 @@ plp(void) | |||
| 557 | 557 | ||
| 558 | status = PULL(); | 558 | status = PULL(); |
| 559 | 559 | ||
| 560 | regs.status.carry = (status & (1 << 7)) > 0; | 560 | regs.status.carry = (status & (1 << 7)) != 0; |
| 561 | regs.status.zero = (status & (1 << 6)) > 0; | 561 | regs.status.zero = (status & (1 << 6)) != 0; |
| 562 | regs.status.interrupt_disable = (status & (1 << 5)) > 0; | 562 | regs.status.interrupt_disable = (status & (1 << 5)) != 0; |
| 563 | regs.status.decimal_mode = (status & (1 << 4)) > 0; | 563 | regs.status.decimal_mode = (status & (1 << 4)) != 0; |
| 564 | regs.status.brk = (status & (1 << 3)) > 0; | 564 | regs.status.brk = (status & (1 << 3)) != 0; |
| 565 | regs.status.unused = (status & (1 << 2)) > 0; | 565 | regs.status.unused = (status & (1 << 2)) != 0; |
| 566 | regs.status.overflow = (status & (1 << 1)) > 0; | 566 | regs.status.overflow = (status & (1 << 1)) != 0; |
| 567 | regs.status.negative = (status & 1) > 0; | 567 | regs.status.negative = (status & 1) != 0; |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | static void | 570 | static void |
| 571 | rol_acc(void) | 571 | rol_acc(void) |
| 572 | { | 572 | { |
| 573 | uint8_t carry; | 573 | uint8_t carry; |
| 574 | carry = (regs.a & (1 << 7)) > 0; | 574 | carry = (regs.a & (1 << 7)) != 0; |
| 575 | 575 | ||
| 576 | regs.a <<= 1; | 576 | regs.a <<= 1; |
| 577 | regs.a |= regs.status.carry; | 577 | regs.a |= regs.status.carry; |
| @@ -585,7 +585,7 @@ static void | |||
| 585 | rol(uint16_t mem) | 585 | rol(uint16_t mem) |
| 586 | { | 586 | { |
| 587 | uint8_t carry, tmp; | 587 | uint8_t carry, tmp; |
| 588 | carry = (peek(mem) & (1 << 7)) > 0; | 588 | carry = (peek(mem) & (1 << 7)) != 0; |
| 589 | 589 | ||
| 590 | tmp = (peek(mem) << 1) | regs.status.carry; | 590 | tmp = (peek(mem) << 1) | regs.status.carry; |
| 591 | memwrite(mem, tmp); | 591 | memwrite(mem, tmp); |
