bsnes/nall/intrinsics.hpp
Tim Allen 0271d6a12b Update to v094r39 release.
byuu says:

Changelog:
- SNES mid-scanline BGMODE fixes finally merged (can run
  atx2.zip{mode7.smc}+mtest(2).sfc properly now)
- Makefile now discards all built-in rules and variables
- switch on bool warning disabled for GCC now as well (was already
  disabled for Clang)
- when loading a game, if any required files are missing, display
  a warning message box (manifest.bml, program.rom, bios.rom, etc)
- when loading a game (or a game slot), if manifest.bml is missing, it
  will invoke icarus to try and generate it
  - if that fails (icarus is missing or the folder is bad), you will get
    a warning telling you that the manifest can't be loaded

The warning prompt on missing files work for both games and the .sys
folders and their files. For some reason, failing to load the DMG/CGB
BIOS is causing a crash before I can display the modal dialog. I have no
idea why, and the stack frame backtrace is junk.

I also can't seem to abort the failed loading process. If I call
Program::unloadMedia(), I get a nasty segfault. Again with a really
nasty stack trace. So for now, it'll just end up sitting there emulating
an empty ROM (solid black screen.) In time, I'd like to fix that too.

Lastly, I need a better method than popen for Windows. popen is kind of
ugly and flashes a console window for a brief second even if the
application launched is linked with -mwindows. Not sure if there even is
one (I need to read the stdout result, so CreateProcess may not work
unless I do something nasty like "> %tmp%/temp") I'm also using the
regular popen instead of _wpopen, so for this WIP, it won't work if your
game folder has non-English letters in the path.
2015-08-04 19:02:04 +10:00

155 lines
5.2 KiB
C++

#ifndef NALL_INTRINSICS_HPP
#define NALL_INTRINSICS_HPP
namespace nall {
struct Intrinsics {
enum class Compiler : unsigned { Clang, GCC, VisualCPP, Unknown };
enum class Platform : unsigned { Windows, MacOSX, Linux, BSD, Unknown };
enum class API : unsigned { Windows, Posix, Unknown };
enum class Display : unsigned { Windows, Quartz, Xorg, Unknown };
enum class Processor : unsigned { x86, amd64, ARM, PPC32, PPC64, Unknown };
enum class Endian : unsigned { LSB, MSB, Unknown };
static inline auto compiler() -> Compiler;
static inline auto platform() -> Platform;
static inline auto api() -> API;
static inline auto display() -> Display;
static inline auto processor() -> Processor;
static inline auto endian() -> Endian;
};
}
/* Compiler detection */
namespace nall {
#if defined(__clang__)
#define COMPILER_CLANG
auto Intrinsics::compiler() -> Compiler { return Compiler::Clang; }
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wempty-body"
#pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wreturn-type"
#pragma clang diagnostic ignored "-Wswitch"
#pragma clang diagnostic ignored "-Wswitch-bool"
#pragma clang diagnostic ignored "-Wtautological-compare"
#elif defined(__GNUC__)
#define COMPILER_GCC
auto Intrinsics::compiler() -> Compiler { return Compiler::GCC; }
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wswitch-bool"
#elif defined(_MSC_VER)
#define COMPILER_VISUALCPP
auto Intrinsics::compiler() -> Compiler { return Compiler::VisualCPP; }
#pragma warning(disable:4996) //libc "deprecation" warnings
#else
#warning "unable to detect compiler"
#define COMPILER_UNKNOWN
auto Intrinsics::compiler() -> Compiler { return Compiler::Unknown; }
#endif
}
/* Platform detection */
namespace nall {
#if defined(_WIN32)
#define PLATFORM_WINDOWS
#define API_WINDOWS
#define DISPLAY_WINDOWS
auto Intrinsics::platform() -> Platform { return Platform::Windows; }
auto Intrinsics::api() -> API { return API::Windows; }
auto Intrinsics::display() -> Display { return Display::Windows; }
#elif defined(__APPLE__)
#define PLATFORM_MACOSX
#define API_POSIX
#define DISPLAY_QUARTZ
auto Intrinsics::platform() -> Platform { return Platform::MacOSX; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Quartz; }
#elif defined(linux) || defined(__linux__)
#define PLATFORM_LINUX
#define API_POSIX
#define DISPLAY_XORG
auto Intrinsics::platform() -> Platform { return Platform::Linux; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Xorg; }
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_BSD
#define API_POSIX
#define DISPLAY_XORG
auto Intrinsics::platform() -> Platform { return Platform::BSD; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Xorg; }
#else
#warning "unable to detect platform"
#define PLATFORM_UNKNOWN
#define API_UNKNOWN
#define DISPLAY_UNKNOWN
auto Intrinsics::platform() -> Platform { return Platform::Unknown; }
auto Intrinsics::api() -> API { return API::Unknown; }
auto Intrinsics::display() -> Display { return Display::Unknown; }
#endif
}
#if defined(PLATFORM_MACOSX)
#include <machine/endian.h>
#elif defined(PLATFORM_LINUX)
#include <endian.h>
#elif defined(PLATFORM_BSD)
#include <sys/endian.h>
#endif
/* Processor Detection */
namespace nall {
#if defined(__i386__) || defined(_M_IX86)
#define PROCESSOR_X86
auto Intrinsics::processor() -> Processor { return Processor::x86; }
#elif defined(__amd64__) || defined(_M_AMD64)
#define PROCESSOR_AMD64
auto Intrinsics::processor() -> Processor { return Processor::amd64; }
#elif defined(__arm__)
#define PROCESSOR_ARM
auto Intrinsics::processor() -> Processor { return Processor::ARM; }
#elif defined(__ppc64__) || defined(_ARCH_PPC64)
#define PROCESSOR_PPC64
auto Intrinsics::processor() -> Processor { return Processor::PPC64; }
#elif defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC)
#define PROCESSOR_PPC32
auto Intrinsics::processor() -> Processor { return Processor::PPC32; }
#else
#warning "unable to detect processor"
#define PROCESSOR_UNKNOWN
auto Intrinsics::processor() -> Processor { return Processor::Unknown; }
#endif
}
/* Endian detection */
namespace nall {
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64)
#define ENDIAN_LSB
auto Intrinsics::endian() -> Endian { return Endian::LSB; }
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(__powerpc__) || defined(_M_PPC)
#define ENDIAN_MSB
auto Intrinsics::endian() -> Endian { return Endian::MSB; }
#else
#warning "unable to detect endian"
#define ENDIAN_UNKNOWN
auto Intrinsics::endian() -> Endian { return Endian::Unknown; }
#endif
}
#endif