2010-08-09 13:31:09 +00:00
|
|
|
#ifdef PPU_CPP
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
//color addition / subtraction
|
|
|
|
//thanks go to blargg for the optimized algorithms
|
2010-08-09 13:31:09 +00:00
|
|
|
inline uint16 PPU::addsub(uint32 x, uint32 y, bool halve) {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(!regs.color_mode) {
|
|
|
|
if(!halve) {
|
|
|
|
unsigned sum = x + y;
|
|
|
|
unsigned carry = (sum - ((x ^ y) & 0x0421)) & 0x8420;
|
|
|
|
return (sum - carry) | (carry - (carry >> 5));
|
|
|
|
} else {
|
|
|
|
return (x + y - ((x ^ y) & 0x0421)) >> 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned diff = x - y + 0x8420;
|
|
|
|
unsigned borrow = (diff - ((x ^ y) & 0x8420)) & 0x8420;
|
|
|
|
if(!halve) {
|
|
|
|
return (diff - borrow) & (borrow - (borrow >> 5));
|
|
|
|
} else {
|
|
|
|
return (((diff - borrow) & (borrow - (borrow >> 5))) & 0x7bde) >> 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|