mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-02-23 06:32:32 +01:00
byuu says: Changelog: - added Cocoa target: higan can now be compiled for OS X Lion [Cydrak, byuu] - SNES/accuracy profile hires color blending improvements - fixes Marvelous text [AWJ] - fixed a slight bug in SNES/SA-1 VBR support caused by a typo - added support for multi-pass shaders that can load external textures (requires OpenGL 3.2+) - added game library path (used by ananke->Import Game) to Settings->Advanced - system profiles, shaders and cheats database can be stored in "all users" shared folders now (eg /usr/share on Linux) - all configuration files are in BML format now, instead of XML (much easier to read and edit this way) - main window supports drag-and-drop of game folders (but not game files / ZIP archives) - audio buffer clears when entering a modal loop on Windows (prevents audio repetition with DirectSound driver) - a substantial amount of code clean-up (probably the biggest refactoring to date) One highly desired target for this release was to default to the optimal drivers instead of the safest drivers, but because AMD drivers don't seem to like my OpenGL 3.2 driver, I've decided to postpone that. AMD has too big a market share. Hopefully with v093 officially released, we can get some public input on what AMD doesn't like.
81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
#ifndef NALL_BIT_HPP
|
|
#define NALL_BIT_HPP
|
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
namespace nall {
|
|
|
|
template<unsigned bits> inline uintmax_t uclamp(const uintmax_t x) {
|
|
enum : uintmax_t { b = 1ull << (bits - 1), y = b * 2 - 1 };
|
|
return y + ((x - y) & -(x < y)); //min(x, y);
|
|
}
|
|
|
|
template<unsigned bits> inline uintmax_t uclip(const uintmax_t x) {
|
|
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
|
return (x & m);
|
|
}
|
|
|
|
template<unsigned bits> inline intmax_t sclamp(const intmax_t x) {
|
|
enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 };
|
|
return (x > m) ? m : (x < -b) ? -b : x;
|
|
}
|
|
|
|
template<unsigned bits> inline intmax_t sclip(const intmax_t x) {
|
|
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
|
return ((x & m) ^ b) - b;
|
|
}
|
|
|
|
namespace bit {
|
|
constexpr inline uintmax_t mask(const char* s, uintmax_t sum = 0) {
|
|
return (
|
|
*s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) :
|
|
*s == ' ' || *s == '_' ? mask(s + 1, sum) :
|
|
*s ? mask(s + 1, sum << 1) :
|
|
sum
|
|
);
|
|
}
|
|
|
|
constexpr inline uintmax_t test(const char* s, uintmax_t sum = 0) {
|
|
return (
|
|
*s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) :
|
|
*s == ' ' || *s == '_' ? test(s + 1, sum) :
|
|
*s ? test(s + 1, sum << 1) :
|
|
sum
|
|
);
|
|
}
|
|
|
|
//lowest(0b1110) == 0b0010
|
|
constexpr inline uintmax_t lowest(const uintmax_t x) {
|
|
return x & -x;
|
|
}
|
|
|
|
//clear_lowest(0b1110) == 0b1100
|
|
constexpr inline uintmax_t clear_lowest(const uintmax_t x) {
|
|
return x & (x - 1);
|
|
}
|
|
|
|
//set_lowest(0b0101) == 0b0111
|
|
constexpr inline uintmax_t set_lowest(const uintmax_t x) {
|
|
return x | (x + 1);
|
|
}
|
|
|
|
//count number of bits set in a byte
|
|
inline unsigned count(uintmax_t x) {
|
|
unsigned count = 0;
|
|
do count += x & 1; while(x >>= 1);
|
|
return count;
|
|
}
|
|
|
|
//round up to next highest single bit:
|
|
//round(15) == 16, round(16) == 16, round(17) == 32
|
|
inline uintmax_t round(uintmax_t x) {
|
|
if((x & (x - 1)) == 0) return x;
|
|
while(x & (x - 1)) x &= x - 1;
|
|
return x << 1;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|