[xbox] 360 support for common

This commit is contained in:
Ced2911 2013-12-03 18:09:16 +01:00 committed by Unknown W. Brackets
parent 3be063d28a
commit 418d2ac8ce
15 changed files with 110 additions and 39 deletions

View File

@ -19,7 +19,11 @@
#define _ATOMIC_WIN32_H_
#include "Common.h"
#ifndef _XBOX
#include <intrin.h>
#else
#include <ppcintrinsics.h>
#endif
#include "CommonWindows.h"
// Atomic operations are performed in a single step by the CPU. It is

View File

@ -147,7 +147,7 @@ private:
# elif defined __SSE2__
# define _M_SSE 0x200
# endif
#elif ((_MSC_VER >= 1500) || __INTEL_COMPILER) // Visual Studio 2008
#elif ((_MSC_VER >= 1500) || __INTEL_COMPILER) && !defined(_XBOX) // Visual Studio 2008
# define _M_SSE 0x402
#endif

View File

@ -84,7 +84,7 @@ inline u64 __rotr64(u64 x, unsigned int shift){
#define stat64 _stat64
#define fstat64 _fstat64
#define fileno _fileno
#ifndef _XBOX
#if _M_IX86
#define Crash() {__asm int 3}
#else
@ -93,6 +93,9 @@ extern "C" {
}
#define Crash() {DebugBreak();}
#endif // M_IX86
#else
#define Crash() {DebugBreak();}
#endif // _XBOX ndef
#endif // WIN32 ndef
// Generic function to get last error message.

View File

@ -10,6 +10,16 @@
#ifdef _XBOX
#include <xtl.h>
extern "C" void _ReadWriteBarrier();
#pragma intrinsic(_ReadWriteBarrier)
extern "C" void _WriteBarrier();
#pragma intrinsic(_WriteBarrier)
extern "C" void _ReadBarrier();
#pragma intrinsic(_ReadBarrier)
#else
#include <Windows.h>
#endif

View File

@ -32,7 +32,7 @@
#include "ConsoleListener.h" // Common
#include "Atomics.h"
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
const int LOG_PENDING_MAX = 120 * 10000;
const int LOG_LATENCY_DELAY_MS = 20;
const int LOG_SHUTDOWN_DELAY_MS = 250;
@ -50,7 +50,7 @@ volatile u32 ConsoleListener::logPendingWritePos = 0;
ConsoleListener::ConsoleListener() : bHidden(true)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
hConsole = NULL;
bUseColor = true;
@ -61,6 +61,8 @@ ConsoleListener::ConsoleListener() : bHidden(true)
logPending = new char[LOG_PENDING_MAX];
}
++refCount;
#elif defined(_XBOX)
bUseColor = false;
#else
bUseColor = isatty(fileno(stdout));
#endif
@ -101,7 +103,7 @@ bool WINAPI ConsoleHandler(DWORD msgType)
// Name is the window title
void ConsoleListener::Init(bool AutoOpen, int Width, int Height, const char *Title)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
openWidth_ = Width;
openHeight_ = Height;
title_ = ConvertUTF8ToWString(Title);
@ -113,7 +115,7 @@ void ConsoleListener::Init(bool AutoOpen, int Width, int Height, const char *Tit
void ConsoleListener::Open()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
if (!GetConsoleWindow())
{
// Open the console window and create the window handle for GetStdHandle()
@ -147,7 +149,7 @@ void ConsoleListener::Open()
void ConsoleListener::Show(bool bShow)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
if (bShow && bHidden)
{
if (!IsOpen())
@ -166,7 +168,7 @@ void ConsoleListener::Show(bool bShow)
void ConsoleListener::UpdateHandle()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
#endif
}
@ -174,7 +176,7 @@ void ConsoleListener::UpdateHandle()
// Close the console window and close the eventual file handle
void ConsoleListener::Close()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
if (hConsole == NULL)
return;
@ -212,7 +214,7 @@ void ConsoleListener::Close()
bool ConsoleListener::IsOpen()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
return (hConsole != NULL);
#else
return true;
@ -226,7 +228,7 @@ bool ConsoleListener::IsOpen()
void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
BOOL SB, SW;
if (BufferFirst)
{
@ -251,7 +253,7 @@ void ConsoleListener::BufferWidthHeight(int BufferWidth, int BufferHeight, int S
void ConsoleListener::LetterSpace(int Width, int Height)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
// Get console info
CONSOLE_SCREEN_BUFFER_INFO ConInfo;
GetConsoleScreenBufferInfo(hConsole, &ConInfo);
@ -277,7 +279,7 @@ void ConsoleListener::LetterSpace(int Width, int Height)
#endif
}
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
COORD ConsoleListener::GetCoordinates(int BytesRead, int BufferWidth)
{
COORD Ret = {0, 0};
@ -502,7 +504,7 @@ void ConsoleListener::WriteToConsole(LogTypes::LOG_LEVELS Level, const char *Tex
void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool Resize)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
// Check size
if (Width < 8 || Height < 12) return;
@ -589,7 +591,7 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool
void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
{
#if defined(_WIN32)
#if defined(_WIN32) && !defined(_XBOX)
if (hThread == NULL && IsOpen())
WriteToConsole(Level, Text, strlen(Text));
else
@ -623,7 +625,7 @@ void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
void ConsoleListener::ClearScreen(bool Cursor)
{
_dbg_assert_msg_(COMMON, IsOpen(), "Don't call this before opening the console.");
#if defined(_WIN32)
#if defined(_WIN32) && !defined(_XBOX)
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;

View File

@ -38,7 +38,7 @@ public:
void LetterSpace(int Width, int Height);
void BufferWidthHeight(int BufferWidth, int BufferHeight, int ScreenWidth, int ScreenHeight, bool BufferFirst);
void PixelSpace(int Left, int Top, int Width, int Height, bool);
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
COORD GetCoordinates(int BytesRead, int BufferWidth);
#endif
void Log(LogTypes::LOG_LEVELS, const char *Text);
@ -47,7 +47,7 @@ public:
void Show(bool bShow);
bool Hidden() const { return bHidden; }
private:
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
HWND GetHwnd(void);
HANDLE hConsole;

View File

@ -20,9 +20,11 @@
#ifdef _WIN32
#include "CommonWindows.h"
#ifndef _XBOX
#include <shlobj.h> // for SHGetFolderPath
#include <shellapi.h>
#include <commdlg.h> // for GetSaveFileName
#endif
#include <io.h>
#include <direct.h> // getcwd
#else
@ -638,6 +640,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
std::string GetCurrentDir()
{
char *dir;
#ifndef _XBOX
// Get the current working directory (getcwd uses malloc)
if (!(dir = __getcwd(NULL, 0))) {
@ -648,12 +651,19 @@ std::string GetCurrentDir()
std::string strDir = dir;
free(dir);
return strDir;
#else
return "game:\\";
#endif
}
// Sets the current directory to the given directory
bool SetCurrentDir(const std::string &directory)
{
#ifndef _XBOX
return __chdir(directory.c_str()) == 0;
#else
return false;
#endif
}
const std::string &GetExeDirectory()
@ -661,6 +671,7 @@ const std::string &GetExeDirectory()
static std::string ExePath;
if (ExePath.empty())
#ifndef _XBOX
{
#ifdef _WIN32
TCHAR program_path[4096] = {0};
@ -697,6 +708,10 @@ const std::string &GetExeDirectory()
}
return ExePath;
#else
static std::wstring ExePath = L"game:\\";
return ExePath;
#endif
}
@ -789,6 +804,7 @@ bool IOFile::Flush()
bool IOFile::Resize(u64 size)
{
#ifndef _XBOX
if (!IsOpen() || 0 !=
#ifdef _WIN32
// ector: _chsize sucks, not 64-bit safe
@ -802,6 +818,10 @@ bool IOFile::Resize(u64 size)
m_good = false;
return m_good;
#else
// TODO: Implement.
return false;
#endif
}
} // namespace

View File

@ -15,7 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
#include <windows.h>
#endif
@ -336,7 +336,7 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
{
bool azerty = false;
bool qwertz = false;
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
HKL localeId = GetKeyboardLayout(0);
// TODO: Is this list complete enough?
switch ((int)localeId & 0xFFFF) {

View File

@ -94,7 +94,7 @@ LogManager::LogManager() {
}
// Remove file logging on small devices
#if !defined(MOBILE_DEVICE) || defined(_DEBUG)
#if !(defined(MOBILE_DEVICE) || defined(_XBOX)) || defined(_DEBUG)
fileLog_ = new FileLogListener("");
consoleLog_ = new ConsoleListener();
debuggerLog_ = new DebuggerLogListener();
@ -106,10 +106,10 @@ LogManager::LogManager() {
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) {
log_[i]->SetEnable(true);
#if !defined(MOBILE_DEVICE) || defined(_DEBUG)
#if !(defined(MOBILE_DEVICE) || defined(_XBOX)) || defined(_DEBUG)
log_[i]->AddListener(fileLog_);
log_[i]->AddListener(consoleLog_);
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(_XBOX)
if (IsDebuggerPresent() && debuggerLog_ != NULL && LOG_MSC_OUTPUTDEBUG)
log_[i]->AddListener(debuggerLog_);
#endif

View File

@ -108,7 +108,7 @@ std::string ram_temp_file = "/home/user/gc_mem.tmp";
#else
std::string ram_temp_file = "/tmp/gc_mem.tmp";
#endif
#else
#elif !defined(_XBOX)
SYSTEM_INFO sysInfo;
#endif
@ -116,7 +116,11 @@ SYSTEM_INFO sysInfo;
// Windows mappings need to be on 64K boundaries, due to Alpha legacy.
#ifdef _WIN32
size_t roundup(size_t x) {
#ifndef _XBOX
int gran = sysInfo.dwAllocationGranularity ? sysInfo.dwAllocationGranularity : 0x10000;
#else
int gran = 0x10000; // 64k in 360
#endif
return (x + gran - 1) & ~(gran - 1);
}
#else
@ -129,8 +133,10 @@ size_t roundup(size_t x) {
void MemArena::GrabLowMemSpace(size_t size)
{
#ifdef _WIN32
#ifndef _XBOX
hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, (DWORD)(size), NULL);
GetSystemInfo(&sysInfo);
#endif
#elif defined(ANDROID)
// Use ashmem so we don't have to allocate a file on disk!
fd = ashmem_create_region("PPSSPP_RAM", size);
@ -176,9 +182,16 @@ void MemArena::ReleaseSpace()
void *MemArena::CreateView(s64 offset, size_t size, void *base)
{
#ifdef _WIN32
#ifdef _XBOX
size = roundup(size);
// use 64kb pages
void * ptr = VirtualAlloc(NULL, size, MEM_COMMIT|MEM_LARGE_PAGES, PAGE_READWRITE);
return ptr;
#else
size = roundup(size);
void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base);
return ptr;
#endif
#else
void *retval = mmap(base, size, PROT_READ | PROT_WRITE, MAP_SHARED |
// Do not sync memory to underlying file. Linux has this by default.
@ -202,7 +215,9 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base)
void MemArena::ReleaseView(void* view, size_t size)
{
#ifdef _WIN32
#ifndef _XBOX
UnmapViewOfFile(view);
#endif
#elif defined(__SYMBIAN32__)
memmap->Decommit(((int)view - (int)memmap->Base()) & 0x3FFFFFFF, size);
#else
@ -276,6 +291,10 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
size_t position = 0;
size_t last_position = 0;
#if defined(_XBOX)
void *ptr;
#endif
// Zero all the pointers to be sure.
for (int i = 0; i < num_views; i++)
{
@ -300,6 +319,12 @@ static bool Memory_TryBase(u8 *base, const MemoryView *views, int num_views, u32
arena->memmap->Commit(view.virtual_address & 0x3FFFFFFF, view.size);
}
*(view.out_ptr) = (u8*)((int)arena->memmap->Base() + view.virtual_address & 0x3FFFFFFF);
#elif defined(_XBOX)
*(view.out_ptr_low) = (u8*)(base + view.virtual_address);
//arena->memmap->Commit(view.virtual_address & 0x3FFFFFFF, view.size);
ptr = VirtualAlloc(base + (view.virtual_address & 0x3FFFFFFF), view.size, MEM_COMMIT, PAGE_READWRITE);
}
*(view.out_ptr) = (u8*)base + (view.virtual_address & 0x3FFFFFFF);
#else
*(view.out_ptr_low) = (u8*)arena->CreateView(position, view.size);
if (!*view.out_ptr_low)
@ -383,8 +408,16 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
return 0;
}
#else
#ifdef _WIN32
#elif defined(_XBOX)
// Reserve 256MB
u8 *base = (u8*)VirtualAlloc(0, 0x10000000, MEM_RESERVE|MEM_LARGE_PAGES, PAGE_READWRITE);
if (!Memory_TryBase(base, views, num_views, flags, arena))
{
PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
exit(0);
return 0;
}
#elif defined(_WIN32)
// Try a whole range of possible bases. Return once we got a valid one.
u32 max_base_addr = 0x7FFF0000 - 0x10000000;
u8 *base = NULL;
@ -418,8 +451,6 @@ u8 *MemoryMap_Setup(const MemoryView *views, int num_views, u32 flags, MemArena
PanicAlert("MemoryMap_Setup: Failed finding a memory base.");
return 0;
}
#endif
#endif
if (base_attempts)
PanicAlert("No possible memory base pointer found!");

View File

@ -219,4 +219,3 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
#endif
}

View File

@ -33,7 +33,7 @@
const char* GetLastErrorMsg()
{
static const size_t buff_size = 255;
#ifndef _XBOX
#ifdef _WIN32
static __declspec(thread) char err_str[buff_size] = {};
@ -48,4 +48,7 @@ const char* GetLastErrorMsg()
#endif
return err_str;
#else
return "GetLastErrorMsg";
#endif
}

View File

@ -67,7 +67,7 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...)
// Default non library dependent panic alert
bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style)
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
int STYLE = MB_ICONINFORMATION;
if (Style == QUESTION) STYLE = MB_ICONQUESTION;
if (Style == WARNING) STYLE = MB_ICONWARNING;
@ -76,7 +76,6 @@ bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style)
std::wstring wcaption = ConvertUTF8ToWString(caption);
return IDYES == MessageBox(0, wtext.c_str(), wcaption.c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
#else
printf("%s\n", text);
return true;

View File

@ -19,7 +19,9 @@
#ifdef _WIN32
#include "CommonWindows.h"
#ifndef _XBOX
#include <mmsystem.h>
#endif
#include <sys/timeb.h>
#else
#include <sys/time.h>
@ -33,7 +35,9 @@ namespace Common
u32 Timer::GetTimeMs()
{
#ifdef _WIN32
#ifdef _XBOX
return GetTickCount();
#elif defined(_WIN32)
return timeGetTime();
#elif defined(BLACKBERRY)
struct timespec time;
@ -149,14 +153,14 @@ std::string Timer::GetTimeElapsedFormatted() const
// Get current time
void Timer::IncreaseResolution()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
timeBeginPeriod(1);
#endif
}
void Timer::RestoreResolution()
{
#ifdef _WIN32
#if defined(_WIN32) && !defined(_XBOX)
timeEndPeriod(1);
#endif
}

View File

@ -33,10 +33,6 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
//#define _CRT_SECURE_NO_DEPRECATE 1
//#define _CRT_NONSTDC_NO_DEPRECATE 1
#include "CommonWindows.h"
#include <tchar.h>
#include <vector>