Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libsnes/bsnes/snes/alt/ppu-compatibility/render/addsub.cpp
2 views
1
#ifdef PPU_CPP
2
3
//color addition / subtraction
4
//thanks go to blargg for the optimized algorithms
5
inline uint16 PPU::addsub(uint32 x, uint32 y, bool halve) {
6
if(!regs.color_mode) {
7
if(!halve) {
8
unsigned sum = x + y;
9
unsigned carry = (sum - ((x ^ y) & 0x0421)) & 0x8420;
10
return (sum - carry) | (carry - (carry >> 5));
11
} else {
12
return (x + y - ((x ^ y) & 0x0421)) >> 1;
13
}
14
} else {
15
unsigned diff = x - y + 0x8420;
16
unsigned borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420;
17
if(!halve) {
18
return (diff - borrow) & (borrow - (borrow >> 5));
19
} else {
20
return (((diff - borrow) & (borrow - (borrow >> 5))) & 0x7bde) >> 1;
21
}
22
}
23
}
24
25
#endif
26
27