bsnes - fix a boatload of general portability problems
This commit is contained in:
parent
3cf7041e68
commit
401aeda91c
|
@ -11,9 +11,9 @@ struct System : property<System> {
|
||||||
GameBoyColor,
|
GameBoyColor,
|
||||||
};
|
};
|
||||||
readonly<Revision> revision;
|
readonly<Revision> revision;
|
||||||
inline bool dmg() const { return revision == Revision::GameBoy; }
|
inline bool dmg() const { return (Revision)revision == Revision::GameBoy; }
|
||||||
inline bool sgb() const { return revision == Revision::SuperGameBoy; }
|
inline bool sgb() const { return (Revision)revision == Revision::SuperGameBoy; }
|
||||||
inline bool cgb() const { return revision == Revision::GameBoyColor; }
|
inline bool cgb() const { return (Revision)revision == Revision::GameBoyColor; }
|
||||||
|
|
||||||
struct BootROM {
|
struct BootROM {
|
||||||
static const uint8 dmg[ 256];
|
static const uint8 dmg[ 256];
|
||||||
|
|
|
@ -176,7 +176,13 @@ namespace nall {
|
||||||
struct __stat64 data;
|
struct __stat64 data;
|
||||||
_wstat64(utf16_t(filename), &data);
|
_wstat64(utf16_t(filename), &data);
|
||||||
#endif
|
#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) {
|
static time_t timestamp(const string &filename, file::time mode = file::time::create) {
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
#include <nall/windows/utf8.hpp>
|
#include <nall/windows/utf8.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define _USE_MATH_DEFINES 1
|
||||||
|
#endif
|
||||||
|
|
||||||
//=========================
|
//=========================
|
||||||
//standard platform headers
|
//standard platform headers
|
||||||
//=========================
|
//=========================
|
||||||
|
@ -29,10 +33,13 @@
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include <shlobj.h>
|
//#include <shlobj.h> //bizhawk chokes?
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#undef interface
|
#undef interface
|
||||||
#define dllexport __declspec(dllexport)
|
#define dllexport __declspec(dllexport)
|
||||||
|
//bad things happen without these here
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
@ -100,23 +107,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char* userpath(char *path) {
|
inline char* userpath(char *path) {
|
||||||
wchar_t fp[_MAX_PATH] = L"";
|
//TODO BIZHAWK
|
||||||
SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp);
|
return nullptr;
|
||||||
strcpy(path, nall::utf8_t(fp));
|
//wchar_t fp[_MAX_PATH] = L"";
|
||||||
for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
|
//SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, fp);
|
||||||
unsigned length = strlen(path);
|
//strcpy(path, nall::utf8_t(fp));
|
||||||
if(path[length] != '/') strcpy(path + length, "/");
|
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
|
||||||
return path;
|
//unsigned length = strlen(path);
|
||||||
|
//if(path[length] != '/') strcpy(path + length, "/");
|
||||||
|
//return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char* getcwd(char *path) {
|
inline char* getcwd(char *path) {
|
||||||
wchar_t fp[_MAX_PATH] = L"";
|
//TODO BIZHAWK
|
||||||
_wgetcwd(fp, _MAX_PATH);
|
return nullptr;
|
||||||
strcpy(path, nall::utf8_t(fp));
|
//wchar_t fp[_MAX_PATH] = L"";
|
||||||
for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
|
//_wgetcwd(fp, _MAX_PATH);
|
||||||
unsigned length = strlen(path);
|
//strcpy(path, nall::utf8_t(fp));
|
||||||
if(path[length] != '/') strcpy(path + length, "/");
|
//for(unsigned n = 0; path[n]; n++) if(path[n] == '\\') path[n] = '/';
|
||||||
return path;
|
//unsigned length = strlen(path);
|
||||||
|
//if(path[length] != '/') strcpy(path + length, "/");
|
||||||
|
//return path;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
//realpath() already exists
|
//realpath() already exists
|
||||||
|
|
|
@ -48,6 +48,12 @@
|
||||||
//writeonly<foo> bar;
|
//writeonly<foo> bar;
|
||||||
//bar = true;
|
//bar = true;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define DUMB(X)
|
||||||
|
#else
|
||||||
|
#define DUMB(X) X
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nall {
|
namespace nall {
|
||||||
template<typename C> struct property {
|
template<typename C> struct property {
|
||||||
template<typename T> struct traits { typedef T type; };
|
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; }
|
||||||
const T& operator()() const { return value; }
|
const T& operator()() const { return value; }
|
||||||
operator const T&() const { return value; }
|
operator const T&() const { return value; }
|
||||||
private:
|
DUMB(private:)
|
||||||
T* operator->() { return &value; }
|
T* operator->() { return &value; }
|
||||||
operator T&() { return value; }
|
operator T&() { return value; }
|
||||||
const T& operator=(const T& value_) { return value = value_; }
|
const T& operator=(const T& value_) { return value = value_; }
|
||||||
T value;
|
T value;
|
||||||
friend class traits<C>::type;
|
DUMB(friend class traits<C>::type);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> struct writeonly {
|
template<typename T> struct writeonly {
|
||||||
void operator=(const T& value_) { value = value_; }
|
void operator=(const T& value_) { value = value_; }
|
||||||
private:
|
DUMB(private:)
|
||||||
const T* operator->() const { return &value; }
|
const T* operator->() const { return &value; }
|
||||||
const T& operator()() const { return value; }
|
const T& operator()() const { return value; }
|
||||||
operator const T&() const { return value; }
|
operator const T&() const { return value; }
|
||||||
T* operator->() { return &value; }
|
T* operator->() { return &value; }
|
||||||
operator T&() { return value; }
|
operator T&() { return value; }
|
||||||
T value;
|
T value;
|
||||||
friend class traits<C>::type;
|
DUMB(friend class traits<C>::type);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T> struct readwrite {
|
template<typename T> struct readwrite {
|
||||||
|
|
|
@ -108,7 +108,7 @@ void Cartridge::parse_markup_nss(XML::Node &root) {
|
||||||
void Cartridge::parse_markup_icd2(XML::Node &root) {
|
void Cartridge::parse_markup_icd2(XML::Node &root) {
|
||||||
#if defined(GAMEBOY)
|
#if defined(GAMEBOY)
|
||||||
if(root.exists() == false) return;
|
if(root.exists() == false) return;
|
||||||
if(mode != Mode::SuperGameBoy) return;
|
if(mode.value != Mode::SuperGameBoy) return;
|
||||||
|
|
||||||
icd2.revision = max(1, numeral(root["revision"].data));
|
icd2.revision = max(1, numeral(root["revision"].data));
|
||||||
|
|
||||||
|
@ -241,7 +241,8 @@ void Cartridge::parse_markup_necdsp(XML::Node &root) {
|
||||||
if(!sha256.empty()) {
|
if(!sha256.empty()) {
|
||||||
//XML file specified SHA256 sum for program. Verify file matches the hash.
|
//XML file specified SHA256 sum for program. Verify file matches the hash.
|
||||||
fp.seek(0);
|
fp.seek(0);
|
||||||
uint8_t data[filesize];
|
//uint8_t data[filesize]; //test
|
||||||
|
uint8_t *data = (uint8_t*)alloca(filesize);
|
||||||
fp.read(data, filesize);
|
fp.read(data, filesize);
|
||||||
|
|
||||||
if(sha256 != nall::sha256(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) {
|
void Cartridge::parse_markup_bsx(XML::Node &root) {
|
||||||
if(root.exists() == false) return;
|
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;
|
has_bsx_slot = true;
|
||||||
|
|
||||||
for(auto &node : root["slot"]) {
|
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) {
|
void Cartridge::parse_markup_sufamiturbo(XML::Node &root) {
|
||||||
if(root.exists() == false) return;
|
if(root.exists() == false) return;
|
||||||
if(mode != Mode::SufamiTurbo) return;
|
if(mode.value != Mode::SufamiTurbo) return;
|
||||||
|
|
||||||
for(auto &slot : root) {
|
for(auto &slot : root) {
|
||||||
if(slot.name != "slot") continue;
|
if(slot.name != "slot") continue;
|
||||||
|
|
|
@ -155,7 +155,7 @@ void System::power() {
|
||||||
|
|
||||||
region = config.region;
|
region = config.region;
|
||||||
expansion = config.expansion_port;
|
expansion = config.expansion_port;
|
||||||
if(region == Region::Autodetect) {
|
if(region.value == Region::Autodetect) {
|
||||||
region = (cartridge.region() == Cartridge::Region::NTSC ? Region::NTSC : Region::PAL);
|
region = (cartridge.region() == Cartridge::Region::NTSC ? Region::NTSC : Region::PAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue