bsnes - fix a boatload of general portability problems

This commit is contained in:
zeromus 2015-06-18 03:07:00 +00:00
parent 3cf7041e68
commit 401aeda91c
6 changed files with 52 additions and 28 deletions

View File

@ -11,9 +11,9 @@ struct System : property<System> {
GameBoyColor,
};
readonly<Revision> revision;
inline bool dmg() const { return revision == Revision::GameBoy; }
inline bool sgb() const { return revision == Revision::SuperGameBoy; }
inline bool cgb() const { return revision == Revision::GameBoyColor; }
inline bool dmg() const { return (Revision)revision == Revision::GameBoy; }
inline bool sgb() const { return (Revision)revision == Revision::SuperGameBoy; }
inline bool cgb() const { return (Revision)revision == Revision::GameBoyColor; }
struct BootROM {
static const uint8 dmg[ 256];

View File

@ -176,7 +176,13 @@ namespace nall {
struct __stat64 data;
_wstat64(utf16_t(filename), &data);
#endif
return S_ISREG(data.st_mode) ? data.st_size : 0u;
//not readily possible in msvc; not needed in bizhawk
#ifdef BIZHAWK
return data.st_size;
#else
return S_ISREG(data.st_mode) ? data.st_size : 0u; //TEST
#endif
}
static time_t timestamp(const string &filename, file::time mode = file::time::create) {

View File

@ -8,6 +8,10 @@
#include <nall/windows/utf8.hpp>
#endif
#ifdef _MSC_VER
#define _USE_MATH_DEFINES 1
#endif
//=========================
//standard platform headers
//=========================
@ -29,10 +33,13 @@
#if defined(_WIN32)
#include <io.h>
#include <direct.h>
#include <shlobj.h>
//#include <shlobj.h> //bizhawk chokes?
#include <wchar.h>
#undef interface
#define dllexport __declspec(dllexport)
//bad things happen without these here
#include <string>
#include <vector>
#else
#include <unistd.h>
#include <pwd.h>
@ -100,23 +107,27 @@
}
inline char* userpath(char *path) {
wchar_t fp[_MAX_PATH] = L"";
SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp);
strcpy(path, nall::utf8_t(fp));
for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
unsigned length = strlen(path);
if(path[length] != '/') strcpy(path + length, "/");
return path;
//TODO BIZHAWK
return nullptr;
//wchar_t fp[_MAX_PATH] = L"";
//SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp);
//strcpy(path, nall::utf8_t(fp));
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
//unsigned length = strlen(path);
//if(path[length] != '/') strcpy(path + length, "/");
//return path;
}
inline char* getcwd(char *path) {
wchar_t fp[_MAX_PATH] = L"";
_wgetcwd(fp, _MAX_PATH);
strcpy(path, nall::utf8_t(fp));
for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
unsigned length = strlen(path);
if(path[length] != '/') strcpy(path + length, "/");
return path;
//TODO BIZHAWK
return nullptr;
//wchar_t fp[_MAX_PATH] = L"";
//_wgetcwd(fp, _MAX_PATH);
//strcpy(path, nall::utf8_t(fp));
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
//unsigned length = strlen(path);
//if(path[length] != '/') strcpy(path + length, "/");
//return path;
}
#else
//realpath() already exists

View File

@ -48,6 +48,12 @@
//writeonly<foo> bar;
//bar = true;
#ifdef _MSC_VER
#define DUMB(X)
#else
#define DUMB(X) X
#endif
namespace nall {
template<typename C> struct property {
template<typename T> struct traits { typedef T type; };
@ -56,24 +62,24 @@ namespace nall {
const T* operator->() const { return &value; }
const T& operator()() const { return value; }
operator const T&() const { return value; }
private:
DUMB(private:)
T* operator->() { return &value; }
operator T&() { return value; }
const T& operator=(const T& value_) { return value = value_; }
T value;
friend class traits<C>::type;
DUMB(friend class traits<C>::type);
};
template<typename T> struct writeonly {
void operator=(const T& value_) { value = value_; }
private:
DUMB(private:)
const T* operator->() const { return &value; }
const T& operator()() const { return value; }
operator const T&() const { return value; }
T* operator->() { return &value; }
operator T&() { return value; }
T value;
friend class traits<C>::type;
DUMB(friend class traits<C>::type);
};
template<typename T> struct readwrite {

View File

@ -108,7 +108,7 @@ void Cartridge::parse_markup_nss(XML::Node &root) {
void Cartridge::parse_markup_icd2(XML::Node &root) {
#if defined(GAMEBOY)
if(root.exists() == false) return;
if(mode != Mode::SuperGameBoy) return;
if(mode.value != Mode::SuperGameBoy) return;
icd2.revision = max(1, numeral(root["revision"].data));
@ -241,7 +241,8 @@ void Cartridge::parse_markup_necdsp(XML::Node &root) {
if(!sha256.empty()) {
//XML file specified SHA256 sum for program. Verify file matches the hash.
fp.seek(0);
uint8_t data[filesize];
//uint8_t data[filesize]; //test
uint8_t *data = (uint8_t*)alloca(filesize);
fp.read(data, filesize);
if(sha256 != nall::sha256(data, filesize)) {
@ -367,7 +368,7 @@ void Cartridge::parse_markup_armdsp(XML::Node &root) {
void Cartridge::parse_markup_bsx(XML::Node &root) {
if(root.exists() == false) return;
if(mode != Mode::BsxSlotted && mode != Mode::Bsx) return;
if(mode.value != Mode::BsxSlotted && mode.value != Mode::Bsx) return;
has_bsx_slot = true;
for(auto &node : root["slot"]) {
@ -394,7 +395,7 @@ void Cartridge::parse_markup_bsx(XML::Node &root) {
void Cartridge::parse_markup_sufamiturbo(XML::Node &root) {
if(root.exists() == false) return;
if(mode != Mode::SufamiTurbo) return;
if(mode.value != Mode::SufamiTurbo) return;
for(auto &slot : root) {
if(slot.name != "slot") continue;

View File

@ -155,7 +155,7 @@ void System::power() {
region = config.region;
expansion = config.expansion_port;
if(region == Region::Autodetect) {
if(region.value == Region::Autodetect) {
region = (cartridge.region() == Cartridge::Region::NTSC ? Region::NTSC : Region::PAL);
}