bsnes/snesfilter/nall/varint.hpp

122 lines
6.7 KiB
C++
Raw Normal View History

#ifndef NALL_VARINT_HPP
#define NALL_VARINT_HPP
#include <type_traits>
#include <nall/bit.hpp>
#include <nall/static.hpp>
namespace nall {
template<unsigned bits> class uint_t {
private:
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
unsigned data;
public:
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
inline operator unsigned() const { return data; }
inline unsigned operator ++(int) { unsigned r = data; data = uclip<bits>(data + 1); return r; }
inline unsigned operator --(int) { unsigned r = data; data = uclip<bits>(data - 1); return r; }
inline unsigned operator ++() { return data = uclip<bits>(data + 1); }
inline unsigned operator --() { return data = uclip<bits>(data - 1); }
inline unsigned operator =(const unsigned i) { return data = uclip<bits>(i); }
inline unsigned operator |=(const unsigned i) { return data = uclip<bits>(data | i); }
inline unsigned operator ^=(const unsigned i) { return data = uclip<bits>(data ^ i); }
inline unsigned operator &=(const unsigned i) { return data = uclip<bits>(data & i); }
inline unsigned operator<<=(const unsigned i) { return data = uclip<bits>(data << i); }
inline unsigned operator>>=(const unsigned i) { return data = uclip<bits>(data >> i); }
inline unsigned operator +=(const unsigned i) { return data = uclip<bits>(data + i); }
inline unsigned operator -=(const unsigned i) { return data = uclip<bits>(data - i); }
inline unsigned operator *=(const unsigned i) { return data = uclip<bits>(data * i); }
inline unsigned operator /=(const unsigned i) { return data = uclip<bits>(data / i); }
inline unsigned operator %=(const unsigned i) { return data = uclip<bits>(data % i); }
inline uint_t() : data(0) {}
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
inline uint_t(const unsigned i) : data(uclip<bits>(i)) {}
template<int s> inline unsigned operator=(const uint_t<s> &i) { return data = uclip<bits>((unsigned)i); }
template<int s> inline uint_t(const uint_t<s> &i) : data(uclip<bits>(i)) {}
};
template<unsigned bits> class int_t {
private:
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
signed data;
public:
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
inline operator signed() const { return data; }
inline signed operator ++(int) { signed r = data; data = sclip<bits>(data + 1); return r; }
inline signed operator --(int) { signed r = data; data = sclip<bits>(data - 1); return r; }
inline signed operator ++() { return data = sclip<bits>(data + 1); }
inline signed operator --() { return data = sclip<bits>(data - 1); }
inline signed operator =(const signed i) { return data = sclip<bits>(i); }
inline signed operator |=(const signed i) { return data = sclip<bits>(data | i); }
inline signed operator ^=(const signed i) { return data = sclip<bits>(data ^ i); }
inline signed operator &=(const signed i) { return data = sclip<bits>(data & i); }
inline signed operator<<=(const signed i) { return data = sclip<bits>(data << i); }
inline signed operator>>=(const signed i) { return data = sclip<bits>(data >> i); }
inline signed operator +=(const signed i) { return data = sclip<bits>(data + i); }
inline signed operator -=(const signed i) { return data = sclip<bits>(data - i); }
inline signed operator *=(const signed i) { return data = sclip<bits>(data * i); }
inline signed operator /=(const signed i) { return data = sclip<bits>(data / i); }
inline signed operator %=(const signed i) { return data = sclip<bits>(data % i); }
inline int_t() : data(0) {}
Update to v078 release. byuu says: Finally, a new release. I have been very busy finishing up SNES box, cartridge and PCB scanning plus cataloguing the data, however this release still has some significant improvements. Most notably would be randomization on startup. This will help match the behavior of real hardware and uninitialized memory + registers. It should help catch homebrew software that forgets to initialize things properly. Of course, I was not able to test the complete library, so it is possible that if I've randomized anything that should be constant, that this could cause a regression. You can disable this randomization for netplay or to work around any incompatibilities by editing bsnes.cfg and setting snes.random to false. The GUI also received some updates. Widget sizes are now computed based on font sizes, giving it a perfectly native look (because it is native.) I've also added a hotkey remapping screen to the input settings. Not only can you remap inputs to controllers now, but those who did not know the hotkey bindings can now quickly see which ones exist and what they are mapped to. Changelog (since v077): - memory and most registers are now randomly initialized on power-up - fixed auto joypad polling issue in Super Star Wars - fixed .nec and .rtc file extensions (they were missing the dot) [krom] - PPU/accuracy now clears overscan region on any frame when it is disabled - PPU/compatibility no longer auto-blends hires pixels (use NTSC filter for this) - added hotkey remapping dialog to input settings window - added a few new hotkeys, including quick-reset - phoenix API now auto-sizes widgets based on font sizes - file dialog once again remembers previously selected file when possible
2011-04-30 13:12:15 +00:00
inline int_t(const signed i) : data(sclip<bits>(i)) {}
};
class varuint_t {
private:
unsigned data;
unsigned mask;
public:
inline operator unsigned() const { return data; }
inline unsigned operator ++(int) { unsigned r = data; data = (data + 1) & mask; return r; }
inline unsigned operator --(int) { unsigned r = data; data = (data - 1) & mask; return r; }
inline unsigned operator ++() { return data = (data + 1) & mask; }
inline unsigned operator --() { return data = (data - 1) & mask; }
inline unsigned operator =(const unsigned i) { return data = (i) & mask; }
inline unsigned operator |=(const unsigned i) { return data = (data | i) & mask; }
inline unsigned operator ^=(const unsigned i) { return data = (data ^ i) & mask; }
inline unsigned operator &=(const unsigned i) { return data = (data & i) & mask; }
inline unsigned operator<<=(const unsigned i) { return data = (data << i) & mask; }
inline unsigned operator>>=(const unsigned i) { return data = (data >> i) & mask; }
inline unsigned operator +=(const unsigned i) { return data = (data + i) & mask; }
inline unsigned operator -=(const unsigned i) { return data = (data - i) & mask; }
inline unsigned operator *=(const unsigned i) { return data = (data * i) & mask; }
inline unsigned operator /=(const unsigned i) { return data = (data / i) & mask; }
inline unsigned operator %=(const unsigned i) { return data = (data % i) & mask; }
inline void bits(unsigned bits) { mask = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1); data &= mask; }
inline varuint_t() : data(0), mask(~0U) {}
inline varuint_t(const unsigned i) : data(i), mask(~0U) {}
};
class varuintmax_t {
private:
uintmax_t data;
uintmax_t mask;
public:
inline operator uintmax_t() const { return data; }
inline uintmax_t operator ++(int) { uintmax_t r = data; data = (data + 1) & mask; return r; }
inline uintmax_t operator --(int) { uintmax_t r = data; data = (data - 1) & mask; return r; }
inline uintmax_t operator ++() { return data = (data + 1) & mask; }
inline uintmax_t operator --() { return data = (data - 1) & mask; }
inline uintmax_t operator =(const uintmax_t i) { return data = (i) & mask; }
inline uintmax_t operator |=(const uintmax_t i) { return data = (data | i) & mask; }
inline uintmax_t operator ^=(const uintmax_t i) { return data = (data ^ i) & mask; }
inline uintmax_t operator &=(const uintmax_t i) { return data = (data & i) & mask; }
inline uintmax_t operator<<=(const uintmax_t i) { return data = (data << i) & mask; }
inline uintmax_t operator>>=(const uintmax_t i) { return data = (data >> i) & mask; }
inline uintmax_t operator +=(const uintmax_t i) { return data = (data + i) & mask; }
inline uintmax_t operator -=(const uintmax_t i) { return data = (data - i) & mask; }
inline uintmax_t operator *=(const uintmax_t i) { return data = (data * i) & mask; }
inline uintmax_t operator /=(const uintmax_t i) { return data = (data / i) & mask; }
inline uintmax_t operator %=(const uintmax_t i) { return data = (data % i) & mask; }
inline void bits(unsigned bits) { mask = (1ULL << (bits - 1)) + ((1ULL << (bits - 1)) - 1); data &= mask; }
inline varuintmax_t() : data(0), mask(~0ULL) {}
inline varuintmax_t(const uintmax_t i) : data(i), mask(~0ULL) {}
};
}
#endif