mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-29 23:50:01 +02:00
Update to v106r68 release.
byuu says: Changelog: - nall: converted range, iterator, vector to 64-bit - added (very poor) ColecoVision emulation (including Coleco Adam expansion) - added MSX skeleton - added Neo Geo Pocket skeleton - moved audio,video,resource folders into emulator folder - SFC heuristics: BS-X Town cart is "ZBSJ" [hex_usr] The nall change is for future work on things like BPA: I need to be able to handle files larger than 4GB. It is extremely possible that there are still some truncations to 32-bit lurking around, and even more disastrously, possibly some -1s lurking that won't sign-extend to `(uint64_t)0-1`. There's a lot more classes left to do: `string`, `array_view`, `array_span`, etc.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::operator[](uint offset) -> T& {
|
||||
template<typename T> auto vector<T>::operator[](uint64_t offset) -> T& {
|
||||
#ifdef DEBUG
|
||||
struct out_of_bounds {};
|
||||
if(offset >= size()) throw out_of_bounds{};
|
||||
@@ -10,7 +10,7 @@ template<typename T> auto vector<T>::operator[](uint offset) -> T& {
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator[](uint offset) const -> const T& {
|
||||
template<typename T> auto vector<T>::operator[](uint64_t offset) const -> const T& {
|
||||
#ifdef DEBUG
|
||||
struct out_of_bounds {};
|
||||
if(offset >= size()) throw out_of_bounds{};
|
||||
@@ -18,12 +18,12 @@ template<typename T> auto vector<T>::operator[](uint offset) const -> const T& {
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator()(uint offset) -> T& {
|
||||
template<typename T> auto vector<T>::operator()(uint64_t offset) -> T& {
|
||||
while(offset >= size()) append(T());
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator()(uint offset, const T& value) const -> const T& {
|
||||
template<typename T> auto vector<T>::operator()(uint64_t offset, const T& value) const -> const T& {
|
||||
if(offset >= size()) return value;
|
||||
return _pool[offset];
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ template<typename T> auto vector<T>::operator=(const vector<T>& source) -> vecto
|
||||
_size = source._size;
|
||||
_left = 0;
|
||||
_right = 0;
|
||||
for(uint n : range(_size)) new(_pool + n) T(source._pool[n]);
|
||||
for(uint64_t n : range(_size)) new(_pool + n) T(source._pool[n]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -5,7 +5,7 @@ namespace nall {
|
||||
template<typename T> auto vector<T>::operator==(const vector<T>& source) const -> bool {
|
||||
if(this == &source) return true;
|
||||
if(size() != source.size()) return false;
|
||||
for(uint n = 0; n < size(); n++) {
|
||||
for(uint64_t n = 0; n < size(); n++) {
|
||||
if(operator[](n) != source[n]) return false;
|
||||
}
|
||||
return true;
|
||||
|
@@ -31,11 +31,11 @@ template<typename T> vector<T>::operator array_view<T>() const {
|
||||
return {data(), size()};
|
||||
}
|
||||
|
||||
template<typename T> template<typename Cast> auto vector<T>::capacity() const -> uint {
|
||||
template<typename T> template<typename Cast> auto vector<T>::capacity() const -> uint64_t {
|
||||
return (_left + _size + _right) * sizeof(T) / sizeof(Cast);
|
||||
}
|
||||
|
||||
template<typename T> template<typename Cast> auto vector<T>::size() const -> uint {
|
||||
template<typename T> template<typename Cast> auto vector<T>::size() const -> uint64_t {
|
||||
return _size * sizeof(T) / sizeof(Cast);
|
||||
}
|
||||
|
||||
|
@@ -4,50 +4,50 @@ namespace nall {
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator {
|
||||
vector_iterator(vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
vector_iterator(vector<T>& self, uint64_t offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator& { return offset++, *this; }
|
||||
|
||||
private:
|
||||
vector<T>& self;
|
||||
uint offset;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator_const {
|
||||
vector_iterator_const(const vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
vector_iterator_const(const vector<T>& self, uint64_t offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> const T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator_const& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator_const& { return offset++, *this; }
|
||||
|
||||
private:
|
||||
const vector<T>& self;
|
||||
uint offset;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator_reverse {
|
||||
vector_iterator_reverse(vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
struct vector_reverse_iterator {
|
||||
vector_reverse_iterator(vector<T>& self, uint64_t offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator_reverse& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator_reverse& { return offset--, *this; }
|
||||
auto operator!=(const vector_reverse_iterator& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_reverse_iterator& { return offset--, *this; }
|
||||
|
||||
private:
|
||||
vector<T>& self;
|
||||
uint offset;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator_reverse_const {
|
||||
vector_iterator_reverse_const(const vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
struct vector_reverse_iterator_const {
|
||||
vector_reverse_iterator_const(const vector<T>& self, uint64_t offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> const T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator_reverse_const& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator_reverse_const& { return offset--, *this; }
|
||||
auto operator!=(const vector_reverse_iterator_const& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_reverse_iterator_const& { return offset--, *this; }
|
||||
|
||||
private:
|
||||
const vector<T>& self;
|
||||
uint offset;
|
||||
uint64_t offset;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ namespace nall {
|
||||
template<typename T> auto vector<T>::reset() -> void {
|
||||
if(!_pool) return;
|
||||
|
||||
for(uint n : range(_size)) _pool[n].~T();
|
||||
for(uint64_t n : range(_size)) _pool[n].~T();
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = nullptr;
|
||||
@@ -19,7 +19,7 @@ template<typename T> auto vector<T>::reset() -> void {
|
||||
|
||||
//acquire ownership of allocated memory
|
||||
|
||||
template<typename T> auto vector<T>::acquire(const T* data, uint size, uint capacity) -> void {
|
||||
template<typename T> auto vector<T>::acquire(const T* data, uint64_t size, uint64_t capacity) -> void {
|
||||
reset();
|
||||
_pool = data;
|
||||
_size = size;
|
||||
@@ -43,12 +43,12 @@ template<typename T> auto vector<T>::release() -> T* {
|
||||
//reserve will not actually shrink the capacity, only expand it
|
||||
//shrinking the capacity would destroy objects, and break amortized growth with reallocate and resize
|
||||
|
||||
template<typename T> auto vector<T>::reserveLeft(uint capacity) -> bool {
|
||||
template<typename T> auto vector<T>::reserveLeft(uint64_t capacity) -> bool {
|
||||
if(_size + _left >= capacity) return false;
|
||||
|
||||
uint left = bit::round(capacity);
|
||||
uint64_t left = bit::round(capacity);
|
||||
auto pool = memory::allocate<T>(left + _right) + (left - _size);
|
||||
for(uint n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
for(uint64_t n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = pool;
|
||||
@@ -57,12 +57,12 @@ template<typename T> auto vector<T>::reserveLeft(uint capacity) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::reserveRight(uint capacity) -> bool {
|
||||
template<typename T> auto vector<T>::reserveRight(uint64_t capacity) -> bool {
|
||||
if(_size + _right >= capacity) return false;
|
||||
|
||||
uint right = bit::round(capacity);
|
||||
uint64_t right = bit::round(capacity);
|
||||
auto pool = memory::allocate<T>(_left + right) + _left;
|
||||
for(uint n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
for(uint64_t n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = pool;
|
||||
@@ -74,7 +74,7 @@ template<typename T> auto vector<T>::reserveRight(uint capacity) -> bool {
|
||||
//reallocation is meant for POD types, to avoid the overhead of initialization
|
||||
//do not use with non-POD types, or they will not be properly constructed or destructed
|
||||
|
||||
template<typename T> auto vector<T>::reallocateLeft(uint size) -> bool {
|
||||
template<typename T> auto vector<T>::reallocateLeft(uint64_t size) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
_pool += _size - size;
|
||||
_left += _size - size;
|
||||
@@ -91,7 +91,7 @@ template<typename T> auto vector<T>::reallocateLeft(uint size) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::reallocateRight(uint size) -> bool {
|
||||
template<typename T> auto vector<T>::reallocateRight(uint64_t size) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
_right += _size - size;
|
||||
_size = size;
|
||||
@@ -108,9 +108,9 @@ template<typename T> auto vector<T>::reallocateRight(uint size) -> bool {
|
||||
|
||||
//resize is meant for non-POD types, and will properly construct objects
|
||||
|
||||
template<typename T> auto vector<T>::resizeLeft(uint size, const T& value) -> bool {
|
||||
template<typename T> auto vector<T>::resizeLeft(uint64_t size, const T& value) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
for(uint n : range(_size - size)) _pool[n].~T();
|
||||
for(uint64_t n : range(_size - size)) _pool[n].~T();
|
||||
_pool += _size - size;
|
||||
_left += _size - size;
|
||||
_size = size;
|
||||
@@ -119,7 +119,7 @@ template<typename T> auto vector<T>::resizeLeft(uint size, const T& value) -> bo
|
||||
if(size > _size) { //grow
|
||||
reserveLeft(size);
|
||||
_pool -= size - _size;
|
||||
for(uint n : nall::reverse(range(size - _size))) new(_pool + n) T(value);
|
||||
for(uint64_t n : nall::reverse(range(size - _size))) new(_pool + n) T(value);
|
||||
_left -= size - _size;
|
||||
_size = size;
|
||||
return true;
|
||||
@@ -127,16 +127,16 @@ template<typename T> auto vector<T>::resizeLeft(uint size, const T& value) -> bo
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::resizeRight(uint size, const T& value) -> bool {
|
||||
template<typename T> auto vector<T>::resizeRight(uint64_t size, const T& value) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
for(uint n : range(size, _size)) _pool[n].~T();
|
||||
for(uint64_t n : range(size, _size)) _pool[n].~T();
|
||||
_right += _size - size;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
if(size > _size) { //grow
|
||||
reserveRight(size);
|
||||
for(uint n : range(_size, size)) new(_pool + n) T(value);
|
||||
for(uint64_t n : range(_size, size)) new(_pool + n) T(value);
|
||||
_right -= size - _size;
|
||||
_size = size;
|
||||
return true;
|
||||
|
@@ -19,7 +19,7 @@ template<typename T> auto vector<T>::prepend(T&& value) -> void {
|
||||
template<typename T> auto vector<T>::prepend(const vector<T>& values) -> void {
|
||||
reserveLeft(size() + values.size());
|
||||
_pool -= values.size();
|
||||
for(uint n : range(values)) new(_pool + n) T(values[n]);
|
||||
for(uint64_t n : range(values)) new(_pool + n) T(values[n]);
|
||||
_left -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
@@ -27,7 +27,7 @@ template<typename T> auto vector<T>::prepend(const vector<T>& values) -> void {
|
||||
template<typename T> auto vector<T>::prepend(vector<T>&& values) -> void {
|
||||
reserveLeft(size() + values.size());
|
||||
_pool -= values.size();
|
||||
for(uint n : range(values)) new(_pool + n) T(move(values[n]));
|
||||
for(uint64_t n : range(values)) new(_pool + n) T(move(values[n]));
|
||||
_left -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
@@ -50,26 +50,26 @@ template<typename T> auto vector<T>::append(T&& value) -> void {
|
||||
|
||||
template<typename T> auto vector<T>::append(const vector<T>& values) -> void {
|
||||
reserveRight(size() + values.size());
|
||||
for(uint n : range(values.size())) new(_pool + _size + n) T(values[n]);
|
||||
for(uint64_t n : range(values.size())) new(_pool + _size + n) T(values[n]);
|
||||
_right -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::append(vector<T>&& values) -> void {
|
||||
reserveRight(size() + values.size());
|
||||
for(uint n : range(values.size())) new(_pool + _size + n) T(move(values[n]));
|
||||
for(uint64_t n : range(values.size())) new(_pool + _size + n) T(move(values[n]));
|
||||
_right -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::insert(uint offset, const T& value) -> void {
|
||||
template<typename T> auto vector<T>::insert(uint64_t offset, const T& value) -> void {
|
||||
if(offset == 0) return prepend(value);
|
||||
if(offset == size() - 1) return append(value);
|
||||
reserveRight(size() + 1);
|
||||
_size++;
|
||||
for(int n = size() - 1; n > offset; n--) {
|
||||
for(int64_t n = size() - 1; n > offset; n--) {
|
||||
_pool[n] = move(_pool[n - 1]);
|
||||
}
|
||||
new(_pool + offset) T(value);
|
||||
@@ -77,21 +77,21 @@ template<typename T> auto vector<T>::insert(uint offset, const T& value) -> void
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::removeLeft(uint length) -> void {
|
||||
template<typename T> auto vector<T>::removeLeft(uint64_t length) -> void {
|
||||
if(length > size()) length = size();
|
||||
resizeLeft(size() - length);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::removeRight(uint length) -> void {
|
||||
template<typename T> auto vector<T>::removeRight(uint64_t length) -> void {
|
||||
if(length > size()) length = size();
|
||||
resizeRight(size() - length);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::remove(uint offset, uint length) -> void {
|
||||
template<typename T> auto vector<T>::remove(uint64_t offset, uint64_t length) -> void {
|
||||
if(offset == 0) return removeLeft(length);
|
||||
if(offset == size() - 1) return removeRight(length);
|
||||
|
||||
for(uint n = offset; n < size(); n++) {
|
||||
for(uint64_t n = offset; n < size(); n++) {
|
||||
if(n + length < size()) {
|
||||
_pool[n] = move(_pool[n + length]);
|
||||
} else {
|
||||
@@ -115,7 +115,7 @@ template<typename T> auto vector<T>::takeRight() -> T {
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::take(uint offset) -> T {
|
||||
template<typename T> auto vector<T>::take(uint64_t offset) -> T {
|
||||
if(offset == 0) return takeLeft();
|
||||
if(offset == size() - 1) return takeRight();
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::fill(const T& value) -> void {
|
||||
for(uint n : range(size())) _pool[n] = value;
|
||||
for(uint64_t n : range(size())) _pool[n] = value;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::sort(const function<bool (const T& lhs, const T& rhs)>& comparator) -> void {
|
||||
@@ -12,24 +12,24 @@ template<typename T> auto vector<T>::sort(const function<bool (const T& lhs, con
|
||||
|
||||
template<typename T> auto vector<T>::reverse() -> void {
|
||||
vector<T> reversed;
|
||||
for(uint n : range(size())) reversed.prepend(_pool[n]);
|
||||
for(uint64_t n : range(size())) reversed.prepend(_pool[n]);
|
||||
operator=(move(reversed));
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::find(const function<bool (const T& lhs)>& comparator) -> maybe<uint> {
|
||||
for(uint n : range(size())) if(comparator(_pool[n])) return n;
|
||||
template<typename T> auto vector<T>::find(const function<bool (const T& lhs)>& comparator) -> maybe<uint64_t> {
|
||||
for(uint64_t n : range(size())) if(comparator(_pool[n])) return n;
|
||||
return nothing;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::find(const T& value) const -> maybe<uint> {
|
||||
for(uint n : range(size())) if(_pool[n] == value) return n;
|
||||
template<typename T> auto vector<T>::find(const T& value) const -> maybe<uint64_t> {
|
||||
for(uint64_t n : range(size())) if(_pool[n] == value) return n;
|
||||
return nothing;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::findSorted(const T& value) const -> maybe<uint> {
|
||||
int l = 0, r = size() - 1;
|
||||
template<typename T> auto vector<T>::findSorted(const T& value) const -> maybe<uint64_t> {
|
||||
int64_t l = 0, r = size() - 1;
|
||||
while(l <= r) {
|
||||
int m = l + (r - l >> 1);
|
||||
int64_t m = l + (r - l >> 1);
|
||||
if(value == _pool[m]) return m;
|
||||
value < _pool[m] ? r = m - 1 : l = m + 1;
|
||||
}
|
||||
@@ -37,11 +37,11 @@ template<typename T> auto vector<T>::findSorted(const T& value) const -> maybe<u
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::foreach(const function<void (const T&)>& callback) -> void {
|
||||
for(uint n : range(size())) callback(_pool[n]);
|
||||
for(uint64_t n : range(size())) callback(_pool[n]);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::foreach(const function<void (uint, const T&)>& callback) -> void {
|
||||
for(uint n : range(size())) callback(n, _pool[n]);
|
||||
for(uint64_t n : range(size())) callback(n, _pool[n]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user