Update to v076r07 release.

byuu says:

Rather than make the libsnes API incompatible with previous versions,
I just implemented path as return { basename, hint };
So you will still use the set basename function already there as before.
So either DSP/MSU1/Serial all go in the ROM folder, or they all go
somewhere else. You can be fancy and detect the gametype and override
the basename as you like, if you really want.

Bumped the API to 1.3, and added const char* snes_library_id(void); it
will return "bsnes v076.07" at the moment. The internal string is
static, but don't try caching it or modifying it anyway. You'll have to
split the name and version yourself if you want them separately. API is
backward-compatible to 1.0 still.

Also improved string::assign and string::append to take a variadic
number of arguments. To make this happen, I had to make to_string return
const char* so that infinite recursion did not happen.
This commit is contained in:
Tim Allen 2011-03-17 21:39:55 +11:00
parent 5cbf5b617b
commit 348bace8ed
7 changed files with 56 additions and 37 deletions

View File

@ -12,18 +12,16 @@
namespace nall {
class string;
template<typename T> inline string to_string(T);
template<typename T> inline const char* to_string(T);
class string {
public:
inline void reserve(unsigned);
inline string& assign(const char*);
inline string& append(const char*);
inline string& append(bool);
inline string& append(signed int value);
inline string& append(unsigned int value);
inline string& append(double value);
template<typename... Args> inline string& assign(Args&&... args);
template<typename... Args> inline string& append(Args&&... args);
inline string& assign_(const char*);
inline string& append_(const char*);
inline bool readfile(const string&);

View File

@ -4,14 +4,14 @@
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 integer(v); }
template<> inline string to_string<unsigned int> (unsigned int v) { return decimal(v); }
template<> inline string to_string<double> (double v) { return fp(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<> inline const char* to_string<bool> (bool v) { return v ? "true" : "false"; }
template<> inline const char* to_string<signed int> (signed int v) { static char temp[256]; snprintf(temp, 255, "%+d", v); return temp; }
template<> inline const char* to_string<unsigned int> (unsigned int v) { static char temp[256]; snprintf(temp, 255, "%u", v); return temp; }
template<> inline const char* to_string<double> (double v) { static char temp[256]; snprintf(temp, 255, "%f", v); return temp; }
template<> inline const char* to_string<char*> (char *v) { return v; }
template<> inline const char* to_string<const char*> (const char *v) { return v; }
template<> inline const char* to_string<string> (string v) { return v; }
template<> inline const char* 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)); }
@ -22,8 +22,8 @@ template<typename T> lstring& lstring::operator<<(T value) {
}
#if defined(QSTRING_H)
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(); }
template<> inline const char* to_string<QString>(QString v) { return v.toUtf8().constData(); }
template<> inline const char* to_string<const QString&>(const QString &v) { return v.toUtf8().constData(); }
string::operator QString() const { return QString::fromUtf8(*this); }
#endif

View File

@ -3,6 +3,15 @@
namespace nall {
static void istring(string &output) {
}
template<typename T, typename... Args>
static void istring(string &output, const T &value, Args&&... args) {
output.append_(to_string(value));
istring(output, std::forward<Args>(args)...);
}
void string::reserve(unsigned size_) {
if(size_ > size) {
size = size_;
@ -11,25 +20,31 @@ void string::reserve(unsigned size_) {
}
}
string& string::assign(const char *s) {
template<typename... Args> string& string::assign(Args&&... args) {
*data = 0;
istring(*this, std::forward<Args>(args)...);
return *this;
}
template<typename... Args> string& string::append(Args&&... args) {
istring(*this, std::forward<Args>(args)...);
return *this;
}
string& string::assign_(const char *s) {
unsigned length = strlen(s);
reserve(length);
strcpy(data, s);
return *this;
}
string& string::append(const char *s) {
string& string::append_(const char *s) {
unsigned length = strlen(data) + strlen(s);
reserve(length);
strcat(data, s);
return *this;
}
string& string::append(bool value) { append(value ? "true" : "false"); return *this; }
string& string::append(signed int value) { append(integer(value)); return *this; }
string& string::append(unsigned int value) { append(decimal(value)); return *this; }
string& string::append(double value) { append(fp(value)); return *this; }
string::operator const char*() const {
return data;
}
@ -64,15 +79,6 @@ string& string::operator=(string &&source) {
return *this;
}
static void istring(string &output) {
}
template<typename T, typename... Args>
static void istring(string &output, const T &value, Args&&... args) {
output.append(value);
istring(output, std::forward<Args>(args)...);
}
template<typename... Args> string::string(Args&&... args) {
size = 64;
data = (char*)malloc(size + 1);

View File

@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'qt.moc.hpp'
**
** Created: Mon Mar 14 20:13:45 2011
** Created: Tue Mar 15 13:54:13 2011
** by: The Qt Meta Object Compiler version 62 (Qt 4.7.0)
**
** WARNING! All changes made in this file will be lost!

View File

@ -1,7 +1,7 @@
namespace SNES {
namespace Info {
static const char Name[] = "bsnes";
static const char Version[] = "076.06";
static const char Version[] = "076.07";
static const unsigned SerializerVersion = 18;
}
}

View File

@ -10,6 +10,7 @@ struct Interface : public SNES::Interface {
snes_audio_sample_t paudio_sample;
snes_input_poll_t pinput_poll;
snes_input_state_t pinput_state;
string basename;
void video_refresh(const uint16_t *data, unsigned width, unsigned height) {
if(pvideo_refresh) return pvideo_refresh(data, width, height);
@ -28,18 +29,31 @@ struct Interface : public SNES::Interface {
return 0;
}
void message(const string &text) {
print(text, "\n");
}
string path(SNES::Cartridge::Slot slot, const string &hint) {
return { basename, hint };
}
Interface() : pvideo_refresh(0), paudio_sample(0), pinput_poll(0), pinput_state(0) {
}
};
static Interface interface;
const char* snes_library_id(void) {
static string id = { SNES::Info::Name, " v", SNES::Info::Version };
return (const char*)id;
}
unsigned snes_library_revision_major(void) {
return 1;
}
unsigned snes_library_revision_minor(void) {
return 2;
return 3;
}
void snes_set_video_refresh(snes_video_refresh_t video_refresh) {
@ -63,7 +77,7 @@ void snes_set_controller_port_device(bool port, unsigned device) {
}
void snes_set_cartridge_basename(const char *basename) {
SNES::cartridge.basename = basename;
interface.basename = basename;
}
void snes_init(void) {

View File

@ -71,6 +71,7 @@ typedef void (*snes_audio_sample_t)(uint16_t left, uint16_t right);
typedef void (*snes_input_poll_t)(void);
typedef int16_t (*snes_input_state_t)(bool port, unsigned device, unsigned index, unsigned id);
const char* snes_library_id(void);
unsigned snes_library_revision_major(void);
unsigned snes_library_revision_minor(void);