2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2009-10-07 20:50:39 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-04-14 01:26:57 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-07-03 00:49:40 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-04-14 01:26:57 +00:00
|
|
|
*/
|
2009-04-07 21:54:50 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
// Dependencies.h : Contains classes required by all Utilities headers.
|
2010-08-06 05:46:09 +00:00
|
|
|
// This file is included by most .h files provided by the Utilities class.
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
|
2010-12-14 07:28:05 +00:00
|
|
|
#include "pxForwardDefs.h"
|
2010-10-18 01:40:49 +00:00
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
// This should prove useful....
|
|
|
|
#define wxsFormat wxString::Format
|
|
|
|
|
2010-07-05 19:15:19 +00:00
|
|
|
#ifdef PCSX2_DEBUG
|
2016-11-12 15:28:37 +00:00
|
|
|
#define tryDEBUG try
|
|
|
|
#define catchDEBUG(clause) catch (clause)
|
2010-07-05 19:15:19 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define tryDEBUG if (true)
|
|
|
|
#define catchDEBUG(clause) if (false)
|
2010-07-05 19:15:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(PCSX2_DEVBUILD) || defined(PCSX2_DEBUG)
|
2016-11-12 15:28:37 +00:00
|
|
|
#define tryDEVEL try
|
|
|
|
#define catchDEVEL catch (clause)
|
2010-07-05 19:15:19 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define tryDEBUG if (true)
|
|
|
|
#define catchDEBUG(clause) if (false)
|
2010-07-05 19:15:19 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-18 02:44:27 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ImplementEnumOperators (macro)
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This macro implements ++/-- operators for any conforming enumeration. In order for an
|
|
|
|
// enum to conform, it must have _FIRST and _COUNT members defined, and must have a full
|
|
|
|
// compliment of sequential members (no custom assignments) --- looking like so:
|
|
|
|
//
|
|
|
|
// enum Dummy {
|
|
|
|
// Dummy_FIRST,
|
|
|
|
// Dummy_Item = Dummy_FIRST,
|
|
|
|
// Dummy_Crap,
|
|
|
|
// Dummy_COUNT
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// The macro also defines utility functions for bounds checking enumerations:
|
|
|
|
// EnumIsValid(value); // returns TRUE if the enum value is between FIRST and COUNT.
|
|
|
|
// EnumAssert(value);
|
|
|
|
//
|
|
|
|
// It also defines a *prototype* for converting the enumeration to a string. Note that this
|
|
|
|
// method is not implemented! You must implement it yourself if you want to use it:
|
|
|
|
// EnumToString(value);
|
|
|
|
//
|
2016-11-12 15:28:37 +00:00
|
|
|
#define ImplementEnumOperators(enumName) \
|
|
|
|
static __fi enumName &operator++(enumName &src) \
|
|
|
|
{ \
|
|
|
|
src = (enumName)((int)src + 1); \
|
|
|
|
return src; \
|
|
|
|
} \
|
|
|
|
static __fi enumName &operator--(enumName &src) \
|
|
|
|
{ \
|
|
|
|
src = (enumName)((int)src - 1); \
|
|
|
|
return src; \
|
|
|
|
} \
|
|
|
|
static __fi enumName operator++(enumName &src, int) \
|
|
|
|
{ \
|
|
|
|
enumName orig = src; \
|
|
|
|
src = (enumName)((int)src + 1); \
|
|
|
|
return orig; \
|
|
|
|
} \
|
|
|
|
static __fi enumName operator--(enumName &src, int) \
|
|
|
|
{ \
|
|
|
|
enumName orig = src; \
|
|
|
|
src = (enumName)((int)src - 1); \
|
|
|
|
return orig; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static __fi bool operator<(const enumName &left, const pxEnumEnd_t &) { return (int)left < enumName##_COUNT; } \
|
|
|
|
static __fi bool operator!=(const enumName &left, const pxEnumEnd_t &) { return (int)left != enumName##_COUNT; } \
|
|
|
|
static __fi bool operator==(const enumName &left, const pxEnumEnd_t &) { return (int)left == enumName##_COUNT; } \
|
|
|
|
\
|
|
|
|
static __fi bool EnumIsValid(enumName id) \
|
|
|
|
{ \
|
|
|
|
return ((int)id >= enumName##_FIRST) && ((int)id < enumName##_COUNT); \
|
|
|
|
} \
|
|
|
|
static __fi void EnumAssert(enumName id) \
|
|
|
|
{ \
|
|
|
|
pxAssert(EnumIsValid(id)); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
extern const wxChar *EnumToString(enumName id)
|
|
|
|
|
|
|
|
class pxEnumEnd_t
|
|
|
|
{
|
|
|
|
};
|
2010-06-18 02:44:27 +00:00
|
|
|
static const pxEnumEnd_t pxEnumEnd = {};
|
|
|
|
|
2009-12-03 15:51:39 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// DeclareNoncopyableObject
|
|
|
|
// --------------------------------------------------------------------------------------
|
2009-08-20 14:34:48 +00:00
|
|
|
// This macro provides an easy and clean method for ensuring objects are not copyable.
|
|
|
|
// Simply add the macro to the head or tail of your class declaration, and attempts to
|
|
|
|
// copy the class will give you a moderately obtuse compiler error that will have you
|
2010-06-18 02:44:27 +00:00
|
|
|
// scratching your head for 20 minutes.
|
2009-08-20 14:34:48 +00:00
|
|
|
//
|
|
|
|
// (... but that's probably better than having a weird invalid object copy having you
|
|
|
|
// scratch your head for a day).
|
|
|
|
//
|
|
|
|
// Programmer's notes:
|
|
|
|
// * We intentionally do NOT provide implementations for these methods, which should
|
|
|
|
// never be referenced anyway.
|
|
|
|
|
|
|
|
// * I've opted for macro form over multi-inherited class form (Boost style), because
|
|
|
|
// the errors generated by the macro are considerably less voodoo. The Boost-style
|
|
|
|
// The macro reports the exact class that causes the copy failure, while Boost's class
|
|
|
|
// approach just reports an error in whatever "NoncopyableObject" is inherited.
|
|
|
|
//
|
|
|
|
// * This macro is the same as wxWidgets' DECLARE_NO_COPY_CLASS macro. This one is free
|
|
|
|
// of wx dependencies though, and has a nicer typeset. :)
|
|
|
|
//
|
|
|
|
#ifndef DeclareNoncopyableObject
|
2016-11-12 15:28:37 +00:00
|
|
|
#define DeclareNoncopyableObject(classname) \
|
|
|
|
private: \
|
|
|
|
explicit classname(const classname &); \
|
|
|
|
classname &operator=(const classname &)
|
2009-08-20 14:34:48 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-28 18:03:54 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ScopedBool - Makes sure a boolean is set back to FALSE when current scope is left
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Exception-safe way of tracking entry and exit of various functions of execution zones.
|
|
|
|
//
|
|
|
|
class ScopedBool
|
|
|
|
{
|
|
|
|
protected:
|
2016-11-12 15:28:37 +00:00
|
|
|
bool *m_boolme;
|
2010-06-28 18:03:54 +00:00
|
|
|
|
|
|
|
public:
|
2016-11-12 15:28:37 +00:00
|
|
|
ScopedBool(bool &boolme)
|
|
|
|
{
|
|
|
|
boolme = true;
|
|
|
|
m_boolme = &boolme;
|
|
|
|
}
|
|
|
|
|
|
|
|
~ScopedBool() throw()
|
|
|
|
{
|
|
|
|
*m_boolme = false;
|
|
|
|
}
|
2010-06-28 18:03:54 +00:00
|
|
|
};
|
|
|
|
|
2010-12-14 07:28:05 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// _(x) / _t(x) / _d(x) / pxL(x) / pxLt(x) [macros]
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Define pxWex's own i18n helpers. These override the wxWidgets helpers and provide
|
|
|
|
// additional functionality. Define them FIRST THING, to make sure that wx's own gettext
|
|
|
|
// macros aren't in place.
|
|
|
|
//
|
|
|
|
// _ is for standard translations
|
|
|
|
// _t is for tertiary low priority translations
|
|
|
|
// _d is for debug/devel build translations
|
|
|
|
|
|
|
|
#define WXINTL_NO_GETTEXT_MACRO
|
|
|
|
|
|
|
|
#ifndef _
|
2016-11-12 15:28:37 +00:00
|
|
|
#define _(s) pxGetTranslation(_T(s))
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _t
|
2016-11-12 15:28:37 +00:00
|
|
|
#define _t(s) pxGetTranslation(_T(s))
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _d
|
2016-11-12 15:28:37 +00:00
|
|
|
#define _d(s) pxGetTranslation(_T(s))
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// pxL / pxLt / pxDt -- macros provided for tagging translation strings, without actually running
|
|
|
|
// them through the translator (which the _() does automatically, and sometimes we don't
|
|
|
|
// want that). This is a shorthand replacement for wxTRANSLATE. pxL is a standard translation
|
|
|
|
// moniker. pxLt is for tertiary strings that have a very low translation priority. pxDt is for
|
|
|
|
// debug/devel specific translations.
|
|
|
|
//
|
|
|
|
#ifndef pxL
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxL(a) wxT(a)
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef pxLt
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxLt(a) wxT(a)
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef pxDt
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxDt(a) wxT(a)
|
2010-12-14 07:28:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/intl.h>
|
|
|
|
#include <wx/log.h>
|
2015-06-09 10:40:54 +00:00
|
|
|
#include <wx/crt.h>
|
2016-04-22 23:09:37 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32)
|
2015-06-09 10:40:54 +00:00
|
|
|
// This deals with a mode_t redefinition conflict. The mode_t doesn't seem to be
|
|
|
|
// used anywhere in w32pthreads, so I've chosen to use the wxWidgets mode_t
|
|
|
|
// (I think it's unsigned int vs signed int)
|
|
|
|
#include <wx/filefn.h>
|
|
|
|
#define HAVE_MODE_T
|
2016-02-22 18:36:45 +00:00
|
|
|
#endif
|
2015-06-09 10:40:54 +00:00
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
#include <stdexcept>
|
2016-11-12 15:28:37 +00:00
|
|
|
#include <cstring> // string.h under c++
|
|
|
|
#include <cstdio> // stdio.h under c++
|
2009-07-03 00:49:40 +00:00
|
|
|
#include <cstdlib>
|
2009-11-15 06:26:55 +00:00
|
|
|
#include <vector>
|
2009-10-07 20:50:39 +00:00
|
|
|
#include <list>
|
2015-06-09 10:40:54 +00:00
|
|
|
#include <algorithm>
|
2016-01-26 22:07:52 +00:00
|
|
|
#include <memory>
|
2016-02-22 18:36:45 +00:00
|
|
|
#include <atomic>
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
|
2010-08-06 05:46:09 +00:00
|
|
|
#include "Pcsx2Defs.h"
|
|
|
|
|
2010-12-14 07:28:05 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Handy Human-readable constants for common immediate values (_16kb -> _4gb)
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
static const sptr _1kb = 1024 * 1;
|
|
|
|
static const sptr _4kb = _1kb * 4;
|
|
|
|
static const sptr _16kb = _1kb * 16;
|
|
|
|
static const sptr _32kb = _1kb * 32;
|
|
|
|
static const sptr _64kb = _1kb * 64;
|
|
|
|
static const sptr _128kb = _1kb * 128;
|
|
|
|
static const sptr _256kb = _1kb * 256;
|
2010-10-27 19:18:46 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
static const s64 _1mb = 1024 * 1024;
|
|
|
|
static const s64 _8mb = _1mb * 8;
|
|
|
|
static const s64 _16mb = _1mb * 16;
|
|
|
|
static const s64 _32mb = _1mb * 32;
|
|
|
|
static const s64 _64mb = _1mb * 64;
|
|
|
|
static const s64 _256mb = _1mb * 256;
|
|
|
|
static const s64 _1gb = _1mb * 1024;
|
|
|
|
static const s64 _4gb = _1gb * 4;
|
2010-10-27 19:18:46 +00:00
|
|
|
|
|
|
|
|
2010-08-06 05:46:09 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2012-08-10 10:10:55 +00:00
|
|
|
// pxE(msg) and pxEt(msg) [macros] => now same as _/_t/_d
|
2010-08-06 05:46:09 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxE(english) pxExpandMsg((english))
|
2010-12-02 08:15:11 +00:00
|
|
|
|
|
|
|
// For use with tertiary translations (low priority).
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxEt(english) pxExpandMsg((english))
|
2010-08-06 05:46:09 +00:00
|
|
|
|
2010-12-14 07:28:05 +00:00
|
|
|
// For use with Dev/debug build translations (low priority).
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxE_dev(english) pxExpandMsg((english))
|
2010-12-14 07:28:05 +00:00
|
|
|
|
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
extern const wxChar *__fastcall pxExpandMsg(const wxChar *englishContent);
|
|
|
|
extern const wxChar *__fastcall pxGetTranslation(const wxChar *message);
|
|
|
|
extern bool pxIsEnglish(int id);
|
2010-12-14 07:28:05 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
extern wxString fromUTF8(const char *src);
|
|
|
|
extern wxString fromAscii(const char *src);
|
2010-12-14 07:28:05 +00:00
|
|
|
|
2010-08-06 05:46:09 +00:00
|
|
|
|
2010-10-18 16:09:00 +00:00
|
|
|
#include "Utilities/Assertions.h"
|
|
|
|
#include "Utilities/Exceptions.h"
|
2010-10-18 15:46:05 +00:00
|
|
|
#include "Utilities/ScopedAlloc.h"
|