Initial PS3 compilation support

This commit is contained in:
twinaphex 2012-11-15 18:35:26 +01:00
parent 50b924e3fe
commit 5937957a01
8 changed files with 109 additions and 174 deletions

View File

@ -132,14 +132,16 @@ else ifeq ($(platform), ps3)
CXX = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-g++.exe
AR = $(CELL_SDK)/host-win32/ppu/bin/ppu-lv2-ar.exe
ENDIANNESS_DEFINES := -DMSB_FIRST -DBYTE_ORDER=BIG_ENDIAN
OLD_GCC := 1
else ifeq ($(platform), sncps3)
TARGET := $(TARGET_NAME)_ps3.a
CC = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
CXX = $(CELL_SDK)/host-win32/sn/bin/ps3ppusnc.exe
AR = $(CELL_SDK)/host-win32/sn/bin/ps3snarl.exe
ENDIANNESS_DEFINES := -DMSB_FIRST -DBYTE_ORDER=BIG_ENDIAN
CXXFLAGS += -Xc+=exceptions
OLD_GCC := 1
NO_GCC := 1
else ifeq ($(platform), psl1ght)
TARGET := $(TARGET_NAME)_psl1ght.a
CC = $(PS3DEV)/ppu/bin/ppu-gcc$(EXE_EXT)
@ -174,6 +176,7 @@ else
TARGET := retro.dll
CC = gcc
CXX = g++
IS_X86 = 1
SHARED := -shared -Wl,--no-undefined -Wl,--version-script=link.T
LDFLAGS += -static-libgcc -static-libstdc++ -lwinmm
ENDIANNESS_DEFINES := -DLSB_FIRST
@ -247,34 +250,50 @@ SOURCES_C := $(MPC_SRC) $(TREMOR_SRC) $(LIBRETRO_SOURCES_C) $(TRIO_SOURCES)
SOURCES := $(LIBRETRO_SOURCES) $(CORE_SOURCES) $(MEDNAFEN_SOURCES) $(HW_CPU_SOURCES) $(HW_MISC_SOURCES) $(HW_SOUND_SOURCES) $(HW_VIDEO_SOURCES)
WARNINGS := -Wall \
-Wno-sign-compare \
-Wno-unused-variable \
-Wno-unused-function \
-Wno-uninitialized \
$(NEW_GCC_WARNING_FLAGS) \
-Wno-strict-aliasing
EXTRA_GCC_FLAGS := -funroll-loops -ffast-math
ifeq ($(NO_GCC),1)
EXTRA_GCC_FLAGS :=
WARNINGS :=
FLAGS += -std=gnu99
endif
OBJECTS := $(SOURCES:.cpp=.o) $(SOURCES_C:.c=.o)
all: $(TARGET)
ifeq ($(DEBUG),0)
FLAGS += -O3 -ffast-math -funroll-loops
FLAGS += -O3 $(EXTRA_GCC_FLAGS)
else
FLAGS += -O0 -g
endif
ifneq ($(OLD_GCC),1)
NEW_GCC_WARNING_FLAGS += -Wno-narrowing \
-Wno-unused-but-set-variable \
-Wno-unused-result \
-Wno-overflow
NEW_GCC_FLAGS += -fno-strict-overflow
endif
LDFLAGS += $(fpic) $(SHARED)
FLAGS += -Wall $(fpic) -fno-strict-overflow
FLAGS += $(fpic) $(NEW_GCC_FLAGS)
FLAGS += -I. -Imednafen -Imednafen/include -Imednafen/intl $(CORE_INCDIR)
WARNINGS := -Wall \
-Wno-narrowing \
-Wno-unused-but-set-variable \
-Wno-sign-compare \
-Wno-unused-variable \
-Wno-unused-function \
-Wno-uninitialized \
-Wno-unused-result \
-Wno-strict-aliasing \
-Wno-overflow
FLAGS += $(ENDIANNESS_DEFINES) -DSIZEOF_DOUBLE=8 $(WARNINGS) -DMEDNAFEN_VERSION=\"0.9.26\" -DPACKAGE=\"mednafen\" -DMEDNAFEN_VERSION_NUMERIC=926 -DPSS_STYLE=1 -DMPC_FIXED_POINT $(CORE_DEFINE) -DSTDC_HEADERS -D__STDC_LIMIT_MACROS -D__LIBRETRO__ -DNDEBUG -D_LOW_ACCURACY_ $(EXTRA_INCLUDES)
FLAGS += $(ENDIANNESS_DEFINES) -DSIZEOF_DOUBLE=8 $(WARNINGS) \
-DMEDNAFEN_VERSION=\"0.9.26\" -DPACKAGE=\"mednafen\" -DMEDNAFEN_VERSION_NUMERIC=926 -DPSS_STYLE=1 -DMPC_FIXED_POINT -DARCH_X86 $(CORE_DEFINE) -DSTDC_HEADERS -D__STDC_LIMIT_MACROS -D__LIBRETRO__ -DNDEBUG $(EXTRA_INCLUDES)
ifeq ($(IS_X86), 1)
FLAGS += -DARCH_X86
endif
ifeq ($(CACHE_CD), 1)
FLAGS += -D__LIBRETRO_CACHE_CD__
@ -294,7 +313,7 @@ endif
CXXFLAGS += $(FLAGS)
CFLAGS += $(FLAGS) -std=gnu99
CFLAGS += $(FLAGS)
$(TARGET): $(OBJECTS)
$(CXX) -o $@ $^ $(LDFLAGS)

View File

@ -25,6 +25,10 @@
#include <fcntl.h>
#include <string.h>
#ifdef __CELLOS_LV2__
#include <unistd.h>
#endif
// Some really bad preprocessor abuse follows to handle platforms that don't have fseeko and ftello...and of course
// for largefile support on Windows:

View File

@ -23,114 +23,102 @@
MDFN_Error::MDFN_Error() throw()
{
abort();
abort();
}
MDFN_Error::MDFN_Error(int errno_code_new, const char *format, ...) throw()
{
errno_code = errno_code_new;
errno_code = errno_code_new;
va_list ap;
va_start(ap, format);
error_message = trio_vaprintf(format, ap);
va_end(ap);
va_list ap;
va_start(ap, format);
error_message = trio_vaprintf(format, ap);
va_end(ap);
}
MDFN_Error::MDFN_Error(const ErrnoHolder &enh)
{
errno_code = enh.Errno();
errno_code = enh.Errno();
error_message = trio_aprintf("%s", enh.StrError());
error_message = trio_aprintf("%s", enh.StrError());
}
MDFN_Error::~MDFN_Error() throw()
{
if(error_message)
{
free(error_message);
error_message = NULL;
}
if(error_message)
{
free(error_message);
error_message = NULL;
}
}
MDFN_Error::MDFN_Error(const MDFN_Error &ze_error) throw()
{
if(ze_error.error_message)
error_message = strdup(ze_error.error_message);
else
error_message = NULL;
if(ze_error.error_message)
error_message = strdup(ze_error.error_message);
else
error_message = NULL;
errno_code = ze_error.errno_code;
errno_code = ze_error.errno_code;
}
MDFN_Error& MDFN_Error::operator=(const MDFN_Error &ze_error) throw()
{
char *new_error_message = ze_error.error_message ? strdup(ze_error.error_message) : NULL;
int new_errno_code = ze_error.errno_code;
char *new_error_message = ze_error.error_message ? strdup(ze_error.error_message) : NULL;
int new_errno_code = ze_error.errno_code;
if(error_message)
free(error_message);
if(error_message)
free(error_message);
error_message = new_error_message;
errno_code = new_errno_code;
error_message = new_error_message;
errno_code = new_errno_code;
return(*this);
return(*this);
}
const char * MDFN_Error::what(void) const throw()
{
if(!error_message)
return("Error allocating memory for the error message!");
if(!error_message)
return("Error allocating memory for the error message!");
return(error_message);
return(error_message);
}
int MDFN_Error::GetErrno(void) const throw()
{
return(errno_code);
return(errno_code);
}
static const char *srr_wrap(int ret, const char *local_strerror)
{
if(ret == -1)
return("ERROR IN strerror_r()!!!");
if(ret == -1)
return("ERROR IN strerror_r()!!!");
return(local_strerror);
return(local_strerror);
}
static const char *srr_wrap(const char *ret, const char *local_strerror)
{
if(ret == NULL)
return("ERROR IN strerror_r()!!!");
if(ret == NULL)
return("ERROR IN strerror_r()!!!");
return(ret);
return(ret);
}
void ErrnoHolder::SetErrno(int the_errno)
{
local_errno = the_errno;
local_errno = the_errno;
if(the_errno == 0)
local_strerror[0] = 0;
else
{
#ifdef HAVE_STRERROR_R
const char *retv;
if(the_errno == 0)
local_strerror[0] = 0;
else
{
strncpy(local_strerror, strerror(the_errno), 255);
retv = srr_wrap(strerror_r(the_errno, local_strerror, 256), local_strerror);
if(retv != local_strerror)
strncpy(local_strerror, retv, 255);
#else // No strerror_r :(
strncpy(local_strerror, strerror(the_errno), 255);
#endif
local_strerror[255] = 0;
}
local_strerror[255] = 0;
}
}

View File

@ -183,98 +183,3 @@ void _Huffman_MakeTree( huff_sym_t * sym, unsigned int num_symbols)
_Huffman_MakeCodes(sym, num_symbols);
}
#ifdef __GNUC__
/**
* Print the huffman tables
* print_type = 0 => print the coding table
* print_type = 1 => print the decoding table
* print_type = 2 => print the full codes in symbols order
* print_type = 3 => print the full codes in codes order
* @param sym
* @param num_symbols
* @param print_type
* @param offset
*/
void _Huffman_PrintCodes(huff_sym_t * sym, unsigned int num_symbols, int print_type, int offset)
{
unsigned int total_cnt = 0, total_size = 0, optim_size = 0, i;
int packs[4];
switch( print_type ) {
case 0 :
qsort(sym, num_symbols, sizeof(huff_sym_t),
(int (*)(const void *, const void *)) _Huffman_CompSym);
printf("{\n ");
for( i = 0; i < num_symbols; i++) {
if (i != 0)
printf(", ");
printf("{%u, %u}", sym[i].Code, sym[i].Bits);
}
printf("\n}\n");
break;
case 1:
qsort(sym, num_symbols, sizeof(huff_sym_t),
(int (*)(const void *, const void *)) _Huffman_CompBits);
printf("{\n ");
for( i = num_symbols - 1; i >= 0; i--) {
printf("{0x%.8x, %u, %i}", sym[i].Code << (32 - sym[i].Bits), sym[i].Bits, sym[i].Symbol - offset);
if (i != 0)
printf(", ");
}
printf("\n}\n");
break;
case 4:
qsort(sym, num_symbols, sizeof(huff_sym_t),
(int (*)(const void *, const void *)) _Huffman_CompBits);
printf("{\n ");
for( i = num_symbols - 1; i >= 0; i--) {
int symbol = sym[i].Symbol;
packs[3] = symbol / (offset * offset * offset);
packs[2] = (symbol - packs[3] * offset * offset * offset) / (offset * offset);
packs[1] = (symbol - (packs[3] * offset + packs[2]) * offset * offset) / offset;
packs[0] = symbol - ((packs[3] * offset + packs[2]) * offset + packs[1] * offset);
packs[0] -= offset >> 1;
packs[1] -= offset >> 1;
packs[2] -= offset >> 1;
packs[3] -= offset >> 1;
symbol = ((packs[3] & 15) << 12) | ((packs[2] & 15) << 8) | ((packs[1] & 15) << 4) | (packs[0] & 15);
printf("{0x%.8x, %u, %i}", sym[i].Code << (32 - sym[i].Bits), sym[i].Bits, symbol);
if (i != 0)
printf(", ");
}
printf("\n}\n");
break;
default:
if (print_type == 2)
qsort(sym, num_symbols, sizeof(huff_sym_t),
(int (*)(const void *, const void *)) _Huffman_CompSym);
else
qsort(sym, num_symbols, sizeof(huff_sym_t),
(int (*)(const void *, const void *)) _Huffman_CompBits);
printf("Symbol Count Lenth Code\n");
for( i = 0; i < num_symbols; i++) {
int k = sym[i].Bits - 1;
printf("%-10i %-10u %-10u ", sym[i].Symbol - offset, sym[i].Count, sym[i].Bits);
for (; k >= 0 ; k--)
printf("%u", (sym[i].Code >> k) & 1 );
printf("\n");
total_cnt += sym[i].Count;
total_size += sym[i].Count * sym[i].Bits;
if (sym[i].Count != 0)
optim_size += sym[i].Count * __builtin_log2(sym[i].Count);
}
optim_size = total_cnt * __builtin_log2(total_cnt) - optim_size;
printf("\ncount : %u huff : %f bps ", total_cnt, (float)total_size / total_cnt);
printf("opt : %f bps ", (float)optim_size / total_cnt);
printf("loss : %f bps (%f %%)\n", (float)(total_size - optim_size) / total_cnt, (float)(total_size - optim_size) * 100 / optim_size);
break;
}
}
#endif

View File

@ -43,7 +43,6 @@
#endif
#include <stdlib.h>
#include <memory.h>
#ifdef __cplusplus
extern "C" {

View File

@ -1,10 +1,10 @@
#ifndef _PCE_H
#include "../mednafen-types.h"
#include "../mednafen.h"
#include "../state.h"
#include "../general.h"
#include "../memory.h"
#include "mednafen-types.h"
#include "mednafen.h"
#include "state.h"
#include "general.h"
#include "mednafen-memory.h"
#define PCE_MASTER_CLOCK 21477272.727273

View File

@ -25,6 +25,10 @@
#include "../mempatcher.h"
#include "../cputest/cputest.h"
#ifdef __CELLOS_LV2__
#include <unistd.h>
#endif
#ifdef _MSC_VER
#include "../msvc_compat.h"
#endif

View File

@ -5,6 +5,11 @@
#include "mednafen/general.h"
#include "mednafen/mednafen-driver.h"
#if defined(__CELLOS_LV2__)
#include <sys/timer.h>
#include <ppu_intrinsics.h>
#endif
#ifndef _WIN32
#include <unistd.h>
#endif
@ -22,7 +27,9 @@
void MDFND_Sleep(unsigned int time)
{
#ifdef _WIN32
#if defined(__CELLOS_LV2__)
sys_timer_usleep(time * 1000);
#elif defined(_WIN32)
Sleep(time);
#else
usleep(time * 1000);
@ -94,7 +101,16 @@ uint32 MDFND_GetTime()
static bool first = true;
static uint32_t start_ms;
#ifdef _WIN32
#if defined(__CELLOS_LV2__)
uint64_t time = __mftb();
uint32_t ms = (time - start_ms) / 1000;
if (first)
{
start_ms = ms;
first = false;
}
#elif defined(_WIN32)
DWORD ms = timeGetTime();
if (first)
{