Update to v106r69 release.

byuu says:

The biggest change was improving WonderSwan emulation. With help from
trap15, I tracked down a bug where I was checking the wrong bit for
reverse DMA transfers. Then I also emulated VTOTAL to support variable
refresh rate. Then I improved HyperVoice emulation which should be
unsigned samples in three of four modes. That got Fire Lancer running
great. I also rewrote the disassembler. The old one disassembled many
instructions completely wrong, and deviated too much from any known x86
syntax. I also emulated some of the quirks of the V30 (two-byte POP into
registers fails, SALC is just XLAT mirrored, etc) which probably don't
matter unless someone tries to run code to verify it's a NEC CPU and not
an Intel CPU, but hey, why not?

I also put more work into the MSX skeleton, but it's still just a
skeleton with no real emulation yet.
This commit is contained in:
Tim Allen
2019-01-02 10:52:08 +11:00
parent 3159285eaa
commit aaf094e7c4
115 changed files with 3319 additions and 1394 deletions

View File

@@ -7,10 +7,12 @@
#include <nall/stdint.hpp>
#include <nall/cipher/chacha20.hpp>
#if defined(PLATFORM_LINUX)
#if defined(PLATFORM_LINUX) && __has_include(<sys/random.h>)
#include <sys/random.h>
#elif defined(PLATFORM_WINDOWS)
#elif defined(PLATFORM_WINDOWS) && __has_include(<wincrypt.h>)
#include <wincrypt.h>
#else
#include <stdio.h>
#endif
namespace nall {
@@ -37,18 +39,21 @@ protected:
uint256_t seed = 0;
#if defined(PLATFORM_BSD) || defined(PLATFORM_MACOS)
for(uint n : range(8)) seed = seed << 32 | (uint32_t)arc4random();
#elif defined(PLATFORM_LINUX)
#elif defined(PLATFORM_LINUX) && __has_include(<sys/random.h>)
getrandom(&seed, 32, GRND_NONBLOCK);
#elif defined(PLATFORM_WINDOWS)
#elif defined(PLATFORM_WINDOWS) && __has_include(<wincrypt.h>)
HCRYPTPROV provider;
if(CryptAcquireContext(&provider, nullptr, MS_STRONG_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
CryptGenRandom(provider, 32, (BYTE*)&seed);
CryptReleaseContext(provider, 0);
}
#else
//it's ... better than nothing ...
srand(time(nullptr));
for(uint n : range(32)) seed = seed << 8 | (uint8_t)rand();
if(auto fp = fopen("/dev/urandom", "rb")) {
fread(&seed, 32, 1, fp);
fclose(fp);
}
#endif
return seed;
}

View File

@@ -80,6 +80,9 @@ inline auto binary(uintmax value, long precision = 0, char padchar = '0') -> str
inline auto tokenize(const char* s, const char* p) -> bool;
inline auto tokenize(vector<string>& list, const char* s, const char* p) -> bool;
//utf8.hpp
inline auto characters(string_view self, int offset = 0, int length = -1) -> uint;
//utility.hpp
inline auto slice(string_view self, int offset = 0, int length = -1) -> string;
template<typename T> inline auto fromInteger(char* result, T value) -> char*;
@@ -210,6 +213,12 @@ public:
inline auto findFrom(int offset, string_view source) const -> maybe<uint>;
inline auto ifindFrom(int offset, string_view source) const -> maybe<uint>;
inline auto findNext(int offset, string_view source) const -> maybe<uint>;
inline auto ifindNext(int offset, string_view source) const -> maybe<uint>;
inline auto findPrevious(int offset, string_view source) const -> maybe<uint>;
inline auto ifindPrevious(int offset, string_view source) const -> maybe<uint>;
//format.hpp
inline auto format(const nall::string_format& params) -> type&;
@@ -270,6 +279,9 @@ public:
inline auto stripLeft() -> type&;
inline auto stripRight() -> type&;
//utf8.hpp
inline auto characters(int offset = 0, int length = -1) const -> uint;
//utility.hpp
inline static auto read(string_view filename) -> string;
inline static auto repeat(string_view pattern, uint times) -> string;
@@ -333,6 +345,7 @@ struct string_format : vector<string> {
#include <nall/string/replace.hpp>
#include <nall/string/split.hpp>
#include <nall/string/trim.hpp>
#include <nall/string/utf8.hpp>
#include <nall/string/utility.hpp>
#include <nall/string/vector.hpp>

View File

@@ -13,14 +13,12 @@ auto string::contains(string_view characters) const -> maybe<uint> {
template<bool Insensitive, bool Quoted> auto string::_find(int offset, string_view source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
auto p = data();
for(uint n = offset, quoted = 0; n < size();) {
if(Quoted) { if(p[n] == '\"') { quoted ^= 1; n++; continue; } if(quoted) { n++; continue; } }
if(_compare<Insensitive>(p + n, size() - n, source.data(), source.size())) { n++; continue; }
return n - offset;
}
return nothing;
}
@@ -32,4 +30,36 @@ auto string::iqfind(string_view source) const -> maybe<uint> { return _find<1, 1
auto string::findFrom(int offset, string_view source) const -> maybe<uint> { return _find<0, 0>(offset, source); }
auto string::ifindFrom(int offset, string_view source) const -> maybe<uint> { return _find<1, 0>(offset, source); }
auto string::findNext(int offset, string_view source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
for(int n = offset + 1; n < size(); n++) {
if(memory::compare(data() + n, size() - n, source.data(), source.size()) == 0) return n;
}
return nothing;
}
auto string::ifindNext(int offset, string_view source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
for(int n = offset + 1; n < size(); n++) {
if(memory::icompare(data() + n, size() - n, source.data(), source.size()) == 0) return n;
}
return nothing;
}
auto string::findPrevious(int offset, string_view source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
for(int n = offset - 1; n >= 0; n--) {
if(memory::compare(data() + n, size() - n, source.data(), source.size()) == 0) return n;
}
return nothing;
}
auto string::ifindPrevious(int offset, string_view source) const -> maybe<uint> {
if(source.size() == 0) return nothing;
for(int n = offset - 1; n >= 0; n--) {
if(memory::icompare(data() + n, size() - n, source.data(), source.size()) == 0) return n;
}
return nothing;
}
}

32
nall/string/utf8.hpp Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
namespace nall {
//note: this function assumes the string contains valid UTF-8 characters
//invalid characters will result in an incorrect result from this function
//invalid case 1: byte 1 == 0b'01xxxxxx
//invalid case 2: bytes 2-4 != 0b'10xxxxxx
//invalid case 3: end of string without bytes 2-4 present
auto characters(string_view self, int offset, int length) -> uint {
uint characters = 0;
if(offset < 0) offset = self.size() - abs(offset);
if(offset >= 0 && offset < self.size()) {
if(length < 0) length = self.size() - offset;
if(length >= 0) {
for(int index = offset; index < offset + length;) {
auto byte = self.data()[index++];
if((byte & 0b111'00000) == 0b110'00000) index += 1;
if((byte & 0b1111'0000) == 0b1110'0000) index += 2;
if((byte & 0b11111'000) == 0b11110'000) index += 3;
characters++;
}
}
}
return characters;
}
auto string::characters(int offset, int length) const -> uint {
return nall::characters(*this, offset, length);
}
}