Update to bsnes v062r09 release.

Mostly minor stuff again.

Fixes:
array, linear_vector and pointer_vector need to set source.pool = 0
before calling reset() to avoid destroying the object we're trying to
move.
All of nall::string is inside namespace nall now. No idea what I was
trying to do before with the half-global approach.
nall::function gains a reset() function, more obvious than func =
(void*)0;
The movie file loader wasn't binding the right action when changing
files and clicking load, can't believe nobody noticed that one.
This commit is contained in:
byuu 2010-03-23 12:12:10 +00:00
parent 4179282244
commit 362542924e
23 changed files with 232 additions and 181 deletions

BIN
bsnes.exe

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
static const char bsnesVersion[] = "062.08";
static const char bsnesVersion[] = "062.09";
static const char bsnesTitle[] = "bsnes";
static const unsigned bsnesSerializerVersion = 8;
@ -35,13 +35,4 @@ static const unsigned bsnesSerializerVersion = 8;
#include <nall/vector.hpp>
using namespace nall;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
#include "interface.hpp"

View File

@ -5,6 +5,15 @@
#endif
namespace SNES {
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
struct ChipDebugger {
virtual bool property(unsigned id, string &name, string &value) = 0;
};

View File

@ -92,6 +92,7 @@ namespace nall {
pool = source.pool;
poolsize = source.poolsize;
buffersize = source.buffersize;
source.pool = 0;
source.reset();
return *this;
}

View File

@ -35,6 +35,10 @@ namespace nall {
R operator()(P... p) const { return data.callback(data, p...); }
operator bool() const { return data.callback; }
void reset() {
data.callback = 0;
}
function& operator=(const function &source) { memcpy(&data, &source.data, sizeof(data_t)); return *this; }
function(const function &source) { operator=(source); }

View File

@ -10,42 +10,13 @@
#include <nall/utf8.hpp>
#include <nall/vector.hpp>
inline char chrlower(char c);
inline char chrupper(char c);
inline int stricmp(const char *dest, const char *src);
inline int strpos (const char *str, const char *key);
inline int qstrpos(const char *str, const char *key);
inline bool strbegin (const char *str, const char *key);
inline bool stribegin(const char *str, const char *key);
inline bool strend (const char *str, const char *key);
inline bool striend(const char *str, const char *key);
inline char* strlower(char *str);
inline char* strupper(char *str);
inline char* strtr(char *dest, const char *before, const char *after);
inline uintmax_t strhex (const char *str);
inline intmax_t strsigned (const char *str);
inline uintmax_t strunsigned(const char *str);
inline uintmax_t strbin (const char *str);
inline double strdouble (const char *str);
inline bool match(const char *pattern, const char *str);
inline bool strint (const char *str, int &result);
inline bool strmath(const char *str, int &result);
inline size_t strlcpy(char *dest, const char *src, size_t length);
inline size_t strlcat(char *dest, const char *src, size_t length);
inline char* ltrim(char *str, const char *key = " ");
inline char* rtrim(char *str, const char *key = " ");
inline char* trim (char *str, const char *key = " ");
inline char* ltrim_once(char *str, const char *key = " ");
inline char* rtrim_once(char *str, const char *key = " ");
inline char* trim_once (char *str, const char *key = " ");
namespace nall {
class string;
template<typename T> inline string to_string(T);
class string {
public:
inline void reserve(size_t);
inline void reserve(unsigned);
inline unsigned length() const;
inline string& assign(const char*);
@ -78,7 +49,7 @@ namespace nall {
protected:
char *data;
size_t size;
unsigned size;
#if defined(QT_CORE_LIB)
public:
@ -98,29 +69,69 @@ namespace nall {
lstring(std::initializer_list<string>);
};
//compare.hpp
inline char chrlower(char c);
inline char chrupper(char c);
inline int stricmp(const char *dest, const char *src);
inline int strpos (const char *str, const char *key);
inline int qstrpos(const char *str, const char *key);
inline bool strbegin (const char *str, const char *key);
inline bool stribegin(const char *str, const char *key);
inline bool strend (const char *str, const char *key);
inline bool striend(const char *str, const char *key);
//convert.hpp
inline char* strlower(char *str);
inline char* strupper(char *str);
inline char* strtr(char *dest, const char *before, const char *after);
inline uintmax_t strhex (const char *str);
inline intmax_t strsigned (const char *str);
inline uintmax_t strunsigned(const char *str);
inline uintmax_t strbin (const char *str);
inline double strdouble (const char *str);
//match.hpp
inline bool match(const char *pattern, const char *str);
//math.hpp
inline bool strint (const char *str, int &result);
inline bool strmath(const char *str, int &result);
//strl.hpp
inline unsigned strlcpy(char *dest, const char *src, unsigned length);
inline unsigned strlcat(char *dest, const char *src, unsigned length);
//trim.hpp
inline char* ltrim(char *str, const char *key = " ");
inline char* rtrim(char *str, const char *key = " ");
inline char* trim (char *str, const char *key = " ");
inline char* ltrim_once(char *str, const char *key = " ");
inline char* rtrim_once(char *str, const char *key = " ");
inline char* trim_once (char *str, const char *key = " ");
//utility.hpp
inline unsigned strlcpy(string &dest, const char *src, unsigned length);
inline unsigned strlcat(string &dest, const char *src, unsigned length);
inline string substr(const char *src, unsigned start = 0, unsigned length = 0);
inline string& strlower(string &str);
inline string& strupper(string &str);
inline string& strtr(string &dest, const char *before, const char *after);
inline string& ltrim(string &str, const char *key = " ");
inline string& rtrim(string &str, const char *key = " ");
inline string& trim (string &str, const char *key = " ");
inline string& ltrim_once(string &str, const char *key = " ");
inline string& rtrim_once(string &str, const char *key = " ");
inline string& trim_once (string &str, const char *key = " ");
template<unsigned length = 0, char padding = '0'> inline string strhex(uintmax_t value);
template<unsigned length = 0, char padding = '0'> inline string strsigned(intmax_t value);
template<unsigned length = 0, char padding = '0'> inline string strunsigned(uintmax_t value);
template<unsigned length = 0, char padding = '0'> inline string strbin(uintmax_t value);
inline unsigned strdouble(char *str, double value);
inline string strdouble(double value);
//variadic.hpp
template<typename... Args> inline string sprint(Args... args);
template<typename... Args> inline void print(Args... args);
};
inline size_t strlcpy(nall::string &dest, const char *src, size_t length);
inline size_t strlcat(nall::string &dest, const char *src, size_t length);
inline nall::string& strlower(nall::string &str);
inline nall::string& strupper(nall::string &str);
inline nall::string& strtr(nall::string &dest, const char *before, const char *after);
inline nall::string& ltrim(nall::string &str, const char *key = " ");
inline nall::string& rtrim(nall::string &str, const char *key = " ");
inline nall::string& trim (nall::string &str, const char *key = " ");
inline nall::string& ltrim_once(nall::string &str, const char *key = " ");
inline nall::string& rtrim_once(nall::string &str, const char *key = " ");
inline nall::string& trim_once (nall::string &str, const char *key = " ");
inline nall::string substr(const char *src, size_t start = 0, size_t length = 0);
template<unsigned length = 0, char padding = '0'> inline nall::string strhex(uintmax_t value);
template<unsigned length = 0, char padding = '0'> inline nall::string strsigned(intmax_t value);
template<unsigned length = 0, char padding = '0'> inline nall::string strunsigned(uintmax_t value);
template<unsigned length = 0, char padding = '0'> inline nall::string strbin(uintmax_t value);
inline size_t strdouble(char *str, double value);
inline nall::string strdouble(double value);
#endif

View File

@ -2,28 +2,31 @@
#define NALL_STRING_CAST_HPP
namespace nall {
//this is needed, as C++0x does not support explicit template specialization inside classes
template<> inline string to_string<bool> (bool v) { return v ? "true" : "false"; }
template<> inline string to_string<signed int> (signed int v) { return strsigned(v); }
template<> inline string to_string<unsigned int> (unsigned int v) { return strunsigned(v); }
template<> inline string to_string<double> (double v) { return strdouble(v); }
template<> inline string to_string<char*> (char *v) { return v; }
template<> inline string to_string<const char*> (const char *v) { return v; }
template<> inline string to_string<string> (string v) { return v; }
template<> inline string to_string<const string&>(const string &v) { return v; }
template<typename T> string& string::operator= (T value) { return assign(to_string<T>(value)); }
template<typename T> string& string::operator<<(T value) { return append(to_string<T>(value)); }
//this is needed, as C++0x does not support explicit template specialization inside classes
template<> inline string to_string<bool> (bool v) { return v ? "true" : "false"; }
template<> inline string to_string<signed int> (signed int v) { return strsigned(v); }
template<> inline string to_string<unsigned int> (unsigned int v) { return strunsigned(v); }
template<> inline string to_string<double> (double v) { return strdouble(v); }
template<> inline string to_string<char*> (char *v) { return v; }
template<> inline string to_string<const char*> (const char *v) { return v; }
template<> inline string to_string<string> (string v) { return v; }
template<> inline string to_string<const string&>(const string &v) { return v; }
template<typename T> lstring& lstring::operator<<(T value) {
operator[](size()).assign(to_string<T>(value));
return *this;
}
template<typename T> string& string::operator= (T value) { return assign(to_string<T>(value)); }
template<typename T> string& string::operator<<(T value) { return append(to_string<T>(value)); }
template<typename T> lstring& lstring::operator<<(T value) {
operator[](size()).assign(to_string<T>(value));
return *this;
}
#if defined(QT_CORE_LIB)
template<> inline string to_string<QString>(QString v) { return v.toUtf8().constData(); }
template<> inline string to_string<const QString&>(const QString &v) { return v.toUtf8().constData(); }
string::operator QString() const { return QString::fromUtf8(*this); }
#endif
#if defined(QT_CORE_LIB)
template<> inline string to_string<const QString&>(const QString &v) { return v.toUtf8().constData(); }
string::operator QString() const { return QString::fromUtf8(*this); }
#endif
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef NALL_STRING_COMPARE_HPP
#define NALL_STRING_COMPARE_HPP
namespace nall {
char chrlower(char c) {
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
}
@ -97,4 +99,6 @@ bool striend(const char *str, const char *key) {
return true;
}
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef NALL_STRING_CONVERT_HPP
#define NALL_STRING_CONVERT_HPP
namespace nall {
char* strlower(char *str) {
if(!str) return 0;
int i = 0;
@ -146,4 +148,6 @@ double strdouble(const char *str) {
return !negate ? result : -result;
}
}
#endif

View File

@ -3,7 +3,7 @@
namespace nall {
void string::reserve(size_t size_) {
void string::reserve(unsigned size_) {
if(size_ > size) {
size = size_;
data = (char*)realloc(data, size + 1);
@ -81,6 +81,7 @@ string& string::operator=(string &&source) {
size = source.size;
data = source.data;
source.data = 0;
source.size = 0;
return *this;
}
@ -94,12 +95,12 @@ bool string::readfile(const char *filename) {
#if !defined(_WIN32)
FILE *fp = fopen(filename, "rb");
#else
FILE *fp = _wfopen(nall::utf16_t(filename), L"rb");
FILE *fp = _wfopen(utf16_t(filename), L"rb");
#endif
if(!fp) return false;
fseek(fp, 0, SEEK_END);
size_t size = ftell(fp);
unsigned size = ftell(fp);
rewind(fp);
char *fdata = new char[size + 1];
unsigned unused = fread(fdata, 1, size, fp);

View File

@ -2,59 +2,60 @@
#define NALL_FILENAME_HPP
namespace nall {
// "foo/bar.c" -> "foo/", "bar.c" -> "./"
inline string dir(char const *name) {
string result = name;
for(signed i = strlen(result); i >= 0; i--) {
if(result[i] == '/' || result[i] == '\\') {
result[i + 1] = 0;
break;
}
if(i == 0) result = "./";
}
return result;
}
// "foo/bar.c" -> "bar.c"
inline string notdir(char const *name) {
for(signed i = strlen(name); i >= 0; i--) {
if(name[i] == '/' || name[i] == '\\') {
name += i + 1;
break;
}
// "foo/bar.c" -> "foo/", "bar.c" -> "./"
inline string dir(char const *name) {
string result = name;
for(signed i = strlen(result); i >= 0; i--) {
if(result[i] == '/' || result[i] == '\\') {
result[i + 1] = 0;
break;
}
string result = name;
return result;
if(i == 0) result = "./";
}
return result;
}
// "foo/bar.c" -> "foo/bar"
inline string basename(char const *name) {
string result = name;
for(signed i = strlen(result); i >= 0; i--) {
if(result[i] == '/' || result[i] == '\\') {
//file has no extension
break;
}
if(result[i] == '.') {
result[i] = 0;
break;
}
// "foo/bar.c" -> "bar.c"
inline string notdir(char const *name) {
for(signed i = strlen(name); i >= 0; i--) {
if(name[i] == '/' || name[i] == '\\') {
name += i + 1;
break;
}
return result;
}
string result = name;
return result;
}
// "foo/bar.c" -> "c"
inline string extension(char const *name) {
for(signed i = strlen(name); i >= 0; i--) {
if(name[i] == '.') {
name += i + 1;
break;
}
// "foo/bar.c" -> "foo/bar"
inline string basename(char const *name) {
string result = name;
for(signed i = strlen(result); i >= 0; i--) {
if(result[i] == '/' || result[i] == '\\') {
//file has no extension
break;
}
if(result[i] == '.') {
result[i] = 0;
break;
}
string result = name;
return result;
}
return result;
}
// "foo/bar.c" -> "c"
inline string extension(char const *name) {
for(signed i = strlen(name); i >= 0; i--) {
if(name[i] == '.') {
name += i + 1;
break;
}
}
string result = name;
return result;
}
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef NALL_STRING_MATCH_HPP
#define NALL_STRING_MATCH_HPP
namespace nall {
bool match(const char *p, const char *s) {
const char *p_ = 0, *s_ = 0;
@ -69,4 +71,6 @@ bool match(const char *p, const char *s) {
}
}
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef NALL_STRING_MATH_HPP
#define NALL_STRING_MATH_HPP
namespace nall {
static int eval_integer(const char *&s) {
if(!*s) throw "unrecognized_integer";
int value = 0, x = *s, y = *(s + 1);
@ -157,4 +159,6 @@ bool strmath(const char *s, int &result) {
}
}
}
#endif

View File

@ -1,13 +1,15 @@
#ifndef NALL_STRING_STRL_HPP
#define NALL_STRING_STRL_HPP
namespace nall {
//strlcpy, strlcat based on OpenBSD implementation by Todd C. Miller
//return = strlen(src)
size_t strlcpy(char *dest, const char *src, size_t length) {
unsigned strlcpy(char *dest, const char *src, unsigned length) {
char *d = dest;
const char *s = src;
size_t n = length;
unsigned n = length;
if(n) {
while(--n && (*d++ = *s++)); //copy as many bytes as possible, or until null terminator reached
@ -22,13 +24,13 @@ size_t strlcpy(char *dest, const char *src, size_t length) {
}
//return = strlen(src) + min(length, strlen(dest))
size_t strlcat(char *dest, const char *src, size_t length) {
unsigned strlcat(char *dest, const char *src, unsigned length) {
char *d = dest;
const char *s = src;
size_t n = length;
unsigned n = length;
while(n-- && *d) d++; //find end of dest
size_t dlength = d - dest;
unsigned dlength = d - dest;
n = length - dlength; //subtract length of dest from maximum string length
if(!n) return dlength + strlen(s);
@ -45,4 +47,6 @@ size_t strlcat(char *dest, const char *src, size_t length) {
return dlength + (s - src); //return length of resulting string, sans null terminator
}
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef NALL_STRING_TRIM_HPP
#define NALL_STRING_TRIM_HPP
namespace nall {
char* ltrim(char *str, const char *key) {
if(!key || !*key) return str;
while(strbegin(str, key)) {
@ -47,4 +49,6 @@ char* trim_once(char *str, const char *key) {
return ltrim_once(rtrim_once(str, key), key);
}
}
#endif

View File

@ -1,18 +1,20 @@
#ifndef NALL_STRING_UTILITY_HPP
#define NALL_STRING_UTILITY_HPP
size_t strlcpy(nall::string &dest, const char *src, size_t length) {
namespace nall {
unsigned strlcpy(string &dest, const char *src, unsigned length) {
dest.reserve(length);
return strlcpy(dest(), src, length);
}
size_t strlcat(nall::string &dest, const char *src, size_t length) {
unsigned strlcat(string &dest, const char *src, unsigned length) {
dest.reserve(length);
return strlcat(dest(), src, length);
}
nall::string substr(const char *src, size_t start, size_t length) {
nall::string dest;
string substr(const char *src, unsigned start, unsigned length) {
string dest;
if(length == 0) {
//copy entire string
dest = src + start;
@ -23,22 +25,22 @@ nall::string substr(const char *src, size_t start, size_t length) {
return dest;
}
/* very simplistic wrappers to return nall::string& instead of char* type */
/* very simplistic wrappers to return string& instead of char* type */
nall::string& strlower(nall::string &str) { strlower(str()); return str; }
nall::string& strupper(nall::string &str) { strupper(str()); return str; }
nall::string& strtr(nall::string &dest, const char *before, const char *after) { strtr(dest(), before, after); return dest; }
nall::string& ltrim(nall::string &str, const char *key) { ltrim(str(), key); return str; }
nall::string& rtrim(nall::string &str, const char *key) { rtrim(str(), key); return str; }
nall::string& trim (nall::string &str, const char *key) { trim (str(), key); return str; }
nall::string& ltrim_once(nall::string &str, const char *key) { ltrim_once(str(), key); return str; }
nall::string& rtrim_once(nall::string &str, const char *key) { rtrim_once(str(), key); return str; }
nall::string& trim_once (nall::string &str, const char *key) { trim_once (str(), key); return str; }
string& strlower(string &str) { strlower(str()); return str; }
string& strupper(string &str) { strupper(str()); return str; }
string& strtr(string &dest, const char *before, const char *after) { strtr(dest(), before, after); return dest; }
string& ltrim(string &str, const char *key) { ltrim(str(), key); return str; }
string& rtrim(string &str, const char *key) { rtrim(str(), key); return str; }
string& trim (string &str, const char *key) { trim (str(), key); return str; }
string& ltrim_once(string &str, const char *key) { ltrim_once(str(), key); return str; }
string& rtrim_once(string &str, const char *key) { rtrim_once(str(), key); return str; }
string& trim_once (string &str, const char *key) { trim_once (str(), key); return str; }
/* arithmetic <> string */
template<unsigned length, char padding> nall::string strhex(uintmax_t value) {
nall::string output;
template<unsigned length, char padding> string strhex(uintmax_t value) {
string output;
unsigned offset = 0;
//render string backwards, as we do not know its length yet
@ -61,8 +63,8 @@ template<unsigned length, char padding> nall::string strhex(uintmax_t value) {
return output;
}
template<unsigned length, char padding> nall::string strsigned(intmax_t value) {
nall::string output;
template<unsigned length, char padding> string strsigned(intmax_t value) {
string output;
unsigned offset = 0;
bool negative = value < 0;
@ -87,8 +89,8 @@ template<unsigned length, char padding> nall::string strsigned(intmax_t value) {
return output;
}
template<unsigned length, char padding> nall::string strunsigned(uintmax_t value) {
nall::string output;
template<unsigned length, char padding> string strunsigned(uintmax_t value) {
string output;
unsigned offset = 0;
do {
@ -109,8 +111,8 @@ template<unsigned length, char padding> nall::string strunsigned(uintmax_t value
return output;
}
template<unsigned length, char padding> nall::string strbin(uintmax_t value) {
nall::string output;
template<unsigned length, char padding> string strbin(uintmax_t value) {
string output;
unsigned offset = 0;
do {
@ -134,7 +136,7 @@ template<unsigned length, char padding> nall::string strbin(uintmax_t value) {
//using sprintf is certainly not the most ideal method to convert
//a double to a string ... but attempting to parse a double by
//hand, digit-by-digit, results in subtle rounding errors.
size_t strdouble(char *str, double value) {
unsigned strdouble(char *str, double value) {
char buffer[256];
sprintf(buffer, "%f", value);
@ -155,11 +157,13 @@ size_t strdouble(char *str, double value) {
return length + 1;
}
nall::string strdouble(double value) {
nall::string temp;
string strdouble(double value) {
string temp;
temp.reserve(strdouble(0, value));
strdouble(temp(), value);
return temp;
}
}
#endif

View File

@ -2,24 +2,26 @@
#define NALL_STRING_VARIADIC_HPP
namespace nall {
static void isprint(string &output) {
}
template<typename T, typename... Args>
static void isprint(string &output, T value, Args... args) {
output << to_string<T>(value);
isprint(output, args...);
}
static void isprint(string &output) {
}
template<typename... Args> inline string sprint(Args... args) {
string output;
isprint(output, args...);
return output;
}
template<typename T, typename... Args>
static void isprint(string &output, T value, Args... args) {
output << to_string<T>(value);
isprint(output, args...);
}
template<typename... Args> inline string sprint(Args... args) {
string output;
isprint(output, args...);
return output;
}
template<typename... Args> inline void print(Args... args) {
printf("%s", (const char*)sprint(args...));
}
template<typename... Args> inline void print(Args... args) {
printf("%s", (const char*)sprint(args...));
}
}
#endif

View File

@ -4,8 +4,6 @@
//XML subset parser
//version 0.05
#include <nall/vector.hpp>
namespace nall {
struct xml_attribute {

View File

@ -102,6 +102,7 @@ namespace nall {
pool = source.pool;
poolsize = source.poolsize;
objectsize = source.objectsize;
source.pool = 0;
source.reset();
return *this;
}
@ -210,6 +211,7 @@ namespace nall {
pool = source.pool;
poolsize = source.poolsize;
objectsize = source.objectsize;
source.pool = 0;
source.reset();
return *this;
}

View File

@ -3,9 +3,9 @@
Movie movie;
void Movie::chooseFile() {
fileBrowser->onChange = (void*)0;
fileBrowser->onChange.reset();
fileBrowser->onActivate = bind(&Movie::play, this);
fileBrowser->onChange = bind(&Movie::play, this);
fileBrowser->onAccept = bind(&Movie::play, this);
fileBrowser->setWindowTitle("Select Movie");
fileBrowser->setPath(config().path.current.movie);
fileBrowser->setNameFilters("bsnes Movies (*.bsv)");

View File

@ -50,8 +50,8 @@ void PathSettingWidget::updatePath() {
}
void PathSettingWidget::selectPath() {
fileBrowser->onChange = (void*)0;
fileBrowser->onActivate = (void*)0;
fileBrowser->onChange.reset();
fileBrowser->onActivate.reset();
fileBrowser->onAccept = bind(&PathSettingWidget::acceptPath, this);
fileBrowser->setWindowTitle(pathBrowseLabel);
fileBrowser->setPath(config().path.current.folder);

View File

@ -289,7 +289,7 @@ void VideoSettingsWindow::cropBottomAdjust(int state) {
}
void VideoSettingsWindow::selectFragmentShader() {
fileBrowser->onChange = (void*)0;
fileBrowser->onChange.reset();
fileBrowser->onActivate = bind(&VideoSettingsWindow::assignFragmentShader, this);
fileBrowser->onAccept = bind(&VideoSettingsWindow::assignFragmentShader, this);
fileBrowser->setWindowTitle("Select Fragment Shader");
@ -299,7 +299,7 @@ void VideoSettingsWindow::selectFragmentShader() {
}
void VideoSettingsWindow::selectVertexShader() {
fileBrowser->onChange = (void*)0;
fileBrowser->onChange.reset();
fileBrowser->onActivate = bind(&VideoSettingsWindow::assignVertexShader, this);
fileBrowser->onAccept = bind(&VideoSettingsWindow::assignVertexShader, this);
fileBrowser->setWindowTitle("Select Vertex Shader");