From 401aeda91cbd543706f89a0f5f3107cba8df8e17 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 18 Jun 2015 03:07:00 +0000 Subject: [PATCH] bsnes - fix a boatload of general portability problems --- libsnes/bsnes/gameboy/system/system.hpp | 6 ++-- libsnes/bsnes/nall/file.hpp | 8 ++++- libsnes/bsnes/nall/platform.hpp | 41 ++++++++++++++++--------- libsnes/bsnes/nall/property.hpp | 14 ++++++--- libsnes/bsnes/snes/cartridge/markup.cpp | 9 +++--- libsnes/bsnes/snes/system/system.cpp | 2 +- 6 files changed, 52 insertions(+), 28 deletions(-) diff --git a/libsnes/bsnes/gameboy/system/system.hpp b/libsnes/bsnes/gameboy/system/system.hpp index 18ad757f2f..d98a8357cf 100644 --- a/libsnes/bsnes/gameboy/system/system.hpp +++ b/libsnes/bsnes/gameboy/system/system.hpp @@ -11,9 +11,9 @@ struct System : property { GameBoyColor, }; readonly 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]; diff --git a/libsnes/bsnes/nall/file.hpp b/libsnes/bsnes/nall/file.hpp index 2c26ce56bd..910f284c14 100644 --- a/libsnes/bsnes/nall/file.hpp +++ b/libsnes/bsnes/nall/file.hpp @@ -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) { diff --git a/libsnes/bsnes/nall/platform.hpp b/libsnes/bsnes/nall/platform.hpp index e775ab8fd2..b918bd3cb1 100644 --- a/libsnes/bsnes/nall/platform.hpp +++ b/libsnes/bsnes/nall/platform.hpp @@ -8,6 +8,10 @@ #include #endif +#ifdef _MSC_VER +#define _USE_MATH_DEFINES 1 +#endif + //========================= //standard platform headers //========================= @@ -29,10 +33,13 @@ #if defined(_WIN32) #include #include - #include + //#include //bizhawk chokes? #include #undef interface #define dllexport __declspec(dllexport) + //bad things happen without these here + #include + #include #else #include #include @@ -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 diff --git a/libsnes/bsnes/nall/property.hpp b/libsnes/bsnes/nall/property.hpp index 665afcade0..1e3a70d0d1 100644 --- a/libsnes/bsnes/nall/property.hpp +++ b/libsnes/bsnes/nall/property.hpp @@ -48,6 +48,12 @@ //writeonly bar; //bar = true; +#ifdef _MSC_VER +#define DUMB(X) +#else +#define DUMB(X) X +#endif + namespace nall { template struct property { template 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::type; + DUMB(friend class traits::type); }; template 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::type; + DUMB(friend class traits::type); }; template struct readwrite { diff --git a/libsnes/bsnes/snes/cartridge/markup.cpp b/libsnes/bsnes/snes/cartridge/markup.cpp index 418fcc8eb4..dd46cb2c13 100644 --- a/libsnes/bsnes/snes/cartridge/markup.cpp +++ b/libsnes/bsnes/snes/cartridge/markup.cpp @@ -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; diff --git a/libsnes/bsnes/snes/system/system.cpp b/libsnes/bsnes/snes/system/system.cpp index 41e8a73101..746e7808de 100644 --- a/libsnes/bsnes/snes/system/system.cpp +++ b/libsnes/bsnes/snes/system/system.cpp @@ -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); }