2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
|
2016-06-14 10:51:54 +00:00
|
|
|
#include <nall/algorithm.hpp>
|
2016-05-02 09:57:04 +00:00
|
|
|
#include <nall/stdint.hpp>
|
2016-06-14 10:51:54 +00:00
|
|
|
|
|
|
|
namespace nall { namespace memory {
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto allocate(uint size) -> T*;
|
|
|
|
template<typename T = uint8_t> inline auto allocate(uint size, const T& value) -> T*;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto resize(void* target, uint size) -> T*;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
|
|
|
inline auto free(void* target) -> void;
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto compare(const void* target, uint capacity, const void* source, uint size) -> int;
|
|
|
|
template<typename T = uint8_t> inline auto compare(const void* target, const void* source, uint size) -> int;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto icompare(const void* target, uint capacity, const void* source, uint size) -> int;
|
|
|
|
template<typename T = uint8_t> inline auto icompare(const void* target, const void* source, uint size) -> int;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto copy(void* target, uint capacity, const void* source, uint size) -> T*;
|
|
|
|
template<typename T = uint8_t> inline auto copy(void* target, const void* source, uint size) -> T*;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto move(void* target, uint capacity, const void* source, uint size) -> T*;
|
|
|
|
template<typename T = uint8_t> inline auto move(void* target, const void* source, uint size) -> T*;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T = uint8_t> inline auto fill(void* target, uint capacity, const T& value = {}) -> T*;
|
2016-06-14 10:51:54 +00:00
|
|
|
|
|
|
|
template<typename T> inline auto assign(T* target) -> void {}
|
|
|
|
template<typename T, typename U, typename... P> inline auto assign(T* target, const U& value, P&&... p) -> void;
|
2016-10-27 21:16:58 +00:00
|
|
|
|
|
|
|
template<uint size, typename T = uint64_t> inline auto readl(const void* source) -> T;
|
|
|
|
template<uint size, typename T = uint64_t> inline auto readm(const void* source) -> T;
|
|
|
|
|
|
|
|
template<uint size, typename T = uint64_t> inline auto writel(void* target, T data) -> void;
|
|
|
|
template<uint size, typename T = uint64_t> inline auto writem(void* target, T data) -> void;
|
2016-06-14 10:51:54 +00:00
|
|
|
}}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
namespace nall { namespace memory {
|
2016-06-14 10:51:54 +00:00
|
|
|
|
|
|
|
//implementation notes:
|
|
|
|
//memcmp, memcpy, memmove have terrible performance on small block sizes (FreeBSD 10.0-amd64)
|
|
|
|
//as this library is used extensively by nall/string, and most strings tend to be small,
|
|
|
|
//this library hand-codes these functions instead. surprisingly, it's a substantial speedup
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto allocate(uint size) -> T* {
|
|
|
|
return (T*)malloc(size * sizeof(T));
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto allocate(uint size, const T& value) -> T* {
|
|
|
|
auto result = allocate<T>(size);
|
|
|
|
if(result) fill<T>(result, size, value);
|
2016-06-14 10:51:54 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto resize(void* target, uint size) -> T* {
|
|
|
|
return (T*)realloc(target, size * sizeof(T));
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
auto free(void* target) -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
::free(target);
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto compare(const void* target, uint capacity, const void* source, uint size) -> int {
|
2018-08-21 03:17:12 +00:00
|
|
|
auto t = (uint8_t*)target;
|
|
|
|
auto s = (uint8_t*)source;
|
2018-05-28 01:16:27 +00:00
|
|
|
auto l = min(capacity, size) * sizeof(T);
|
2016-06-14 10:51:54 +00:00
|
|
|
while(l--) {
|
|
|
|
auto x = *t++;
|
|
|
|
auto y = *s++;
|
|
|
|
if(x != y) return x - y;
|
|
|
|
}
|
2018-08-21 03:17:12 +00:00
|
|
|
if(capacity == size) return 0;
|
|
|
|
return -(capacity < size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto compare(const void* target, const void* source, uint size) -> int {
|
|
|
|
return compare<T>(target, size, source, size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto icompare(const void* target, uint capacity, const void* source, uint size) -> int {
|
2018-08-21 03:17:12 +00:00
|
|
|
auto t = (uint8_t*)target;
|
|
|
|
auto s = (uint8_t*)source;
|
2018-05-28 01:16:27 +00:00
|
|
|
auto l = min(capacity, size) * sizeof(T);
|
2016-06-14 10:51:54 +00:00
|
|
|
while(l--) {
|
|
|
|
auto x = *t++;
|
|
|
|
auto y = *s++;
|
|
|
|
if(x - 'A' < 26) x += 32;
|
|
|
|
if(y - 'A' < 26) y += 32;
|
|
|
|
if(x != y) return x - y;
|
|
|
|
}
|
2018-08-21 03:17:12 +00:00
|
|
|
return -(capacity < size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto icompare(const void* target, const void* source, uint size) -> int {
|
|
|
|
return icompare<T>(target, size, source, size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto copy(void* target, uint capacity, const void* source, uint size) -> T* {
|
2016-06-14 10:51:54 +00:00
|
|
|
auto t = (uint8_t*)target;
|
|
|
|
auto s = (uint8_t*)source;
|
2018-05-28 01:16:27 +00:00
|
|
|
auto l = min(capacity, size) * sizeof(T);
|
2016-06-14 10:51:54 +00:00
|
|
|
while(l--) *t++ = *s++;
|
2018-05-28 01:16:27 +00:00
|
|
|
return (T*)target;
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto copy(void* target, const void* source, uint size) -> T* {
|
|
|
|
return copy<T>(target, size, source, size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto move(void* target, uint capacity, const void* source, uint size) -> T* {
|
2016-06-14 10:51:54 +00:00
|
|
|
auto t = (uint8_t*)target;
|
|
|
|
auto s = (uint8_t*)source;
|
2018-05-28 01:16:27 +00:00
|
|
|
auto l = min(capacity, size) * sizeof(T);
|
2016-06-14 10:51:54 +00:00
|
|
|
if(t < s) {
|
|
|
|
while(l--) *t++ = *s++;
|
|
|
|
} else {
|
|
|
|
t += l;
|
|
|
|
s += l;
|
|
|
|
while(l--) *--t = *--s;
|
|
|
|
}
|
2018-05-28 01:16:27 +00:00
|
|
|
return (T*)target;
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto move(void* target, const void* source, uint size) -> T* {
|
|
|
|
return move<T>(target, size, source, size);
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T> auto fill(void* target, uint capacity, const T& value) -> T* {
|
|
|
|
auto t = (T*)target;
|
|
|
|
while(capacity--) *t++ = value;
|
|
|
|
return (T*)target;
|
2016-06-14 10:51:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<typename T, typename U, typename... P> auto assign(T* target, const U& value, P&&... p) -> void {
|
2016-06-14 10:51:54 +00:00
|
|
|
*target++ = value;
|
|
|
|
assign(target, forward<P>(p)...);
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<uint size, typename T> auto readl(const void* source) -> T {
|
2016-10-27 21:16:58 +00:00
|
|
|
auto p = (const uint8_t*)source;
|
|
|
|
T data = 0;
|
|
|
|
for(uint n = 0; n < size; n++) data |= T(*p++) << n * 8;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<uint size, typename T> auto readm(const void* source) -> T {
|
2016-10-27 21:16:58 +00:00
|
|
|
auto p = (const uint8_t*)source;
|
|
|
|
T data = 0;
|
|
|
|
for(int n = size - 1; n >= 0; n--) data |= T(*p++) << n * 8;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<uint size, typename T> auto writel(void* target, T data) -> void {
|
2016-10-27 21:16:58 +00:00
|
|
|
auto p = (uint8_t*)target;
|
|
|
|
for(uint n = 0; n < size; n++) *p++ = data >> n * 8;
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
template<uint size, typename T> auto writem(void* target, T data) -> void {
|
2016-10-27 21:16:58 +00:00
|
|
|
auto p = (uint8_t*)target;
|
|
|
|
for(int n = size - 1; n >= 0; n--) *p++ = data >> n * 8;
|
|
|
|
}
|
|
|
|
|
2018-05-28 01:16:27 +00:00
|
|
|
}}
|