diff --git a/Makefile.ps2 b/Makefile.ps2 index db8ca28523..b84aa8ac33 100644 --- a/Makefile.ps2 +++ b/Makefile.ps2 @@ -5,6 +5,7 @@ HAVE_LOGGER = 0 HAVE_FILE_LOGGER = 0 HAVE_THREADS = 0 BIG_STACK = 0 +MUTE_WARNINGS = 0 PS2_IP = 192.168.1.150 #Configuration for IRX @@ -19,20 +20,26 @@ ifeq ($(DEBUG), 1) RARCH_DEFINES += -DDEBUG else OPTIMIZE_LV := -O2 + LDFLAGS := -s endif +ifeq ($(MUTE_WARNINGS), 1) + DISABLE_WARNINGS := -Wno-sign-compare -Wno-unused -Wno-parentheses +endif + + INCDIR = -I$(PS2DEV)/gsKit/include -I$(PS2SDK)/ports/include INCDIR += -Ips2 -Ips2/include -Ilibretro-common/include INCDIR += -Ideps -Ideps/stb -Ideps/libz -Ideps/7zip -Ideps/pthreads -Ideps/pthreads/platform/ps2 -Ideps/pthreads/platform/helper GPVAL = -G0 -CFLAGS = $(OPTIMIZE_LV) -ffast-math -fsingle-precision-constant +CFLAGS = $(OPTIMIZE_LV) $(DISABLE_WARNINGS) -ffast-math -fsingle-precision-constant ASFLAGS = $(CFLAGS) RARCH_DEFINES += -DPS2 -DUSE_IOP_CTYPE_MACRO -D_MIPS_ARCH_R5900 -DHAVE_ZLIB -DHAVE_RPNG -DHAVE_RJPEG -DWANT_ZLIB RARCH_DEFINES += -DHAVE_GRIFFIN=1 -DRARCH_INTERNAL -DRARCH_CONSOLE -DHAVE_MENU -DHAVE_RGUI -DHAVE_FILTERS_BUILTIN -DHAVE_7ZIP -DHAVE_CC_RESAMPLER LIBDIR = -LDFLAGS = -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ee/lib -L. -s +LDFLAGS += -L$(PS2SDK)/ports/lib -L$(PS2DEV)/gsKit/lib -L$(PS2SDK)/ee/lib -L. LIBS += -lretro_ps2 -lgskit -ldmakit -laudsrv -lpad -lmc -lhdd -lsdl -lfileXio -lpatches -lpoweroff #IRX modules @@ -60,7 +67,7 @@ endif CFLAGS += $(RARCH_DEFINES) # Missing objecst on the PS2SDK -EE_OBJS += ps2/compat_ctype.o +EE_OBJS += ps2/compat_files/compat_ctype.o ps2/compat_files/time.o #EE_OBJS = griffin/griffin.o bootstrap/ps2/kernel_functions.o EE_OBJS += griffin/griffin.o diff --git a/frontend/drivers/platform_ps2.c b/frontend/drivers/platform_ps2.c index 68fddc12bb..51f9a56489 100644 --- a/frontend/drivers/platform_ps2.c +++ b/frontend/drivers/platform_ps2.c @@ -23,7 +23,6 @@ #include #include #include -#include #include @@ -361,8 +360,6 @@ static void frontend_ps2_init(void *data) SifExecModuleBuffer(freesd_irx_start, freesd_irx_size, 0, NULL, NULL); SifExecModuleBuffer(audsrv_irx_start, audsrv_irx_size, 0, NULL, NULL); - SDL_Init(SDL_INIT_TIMER); - /* Initializes audsrv library */ if (audsrv_init()) { diff --git a/gfx/drivers/ps2_gfx.c b/gfx/drivers/ps2_gfx.c index 6770afcc40..ea4383adcf 100644 --- a/gfx/drivers/ps2_gfx.c +++ b/gfx/drivers/ps2_gfx.c @@ -230,7 +230,7 @@ static bool ps2_gfx_frame(void *data, const void *frame, return false; if (frame_count%120==0) { - printf("ps2_gfx_frame %i\n", frame_count); + printf("ps2_gfx_frame %d\n", frame_count); } gsKit_vram_clear(ps2->gsGlobal); diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 51234c1878..ad17f8d51d 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -68,7 +68,6 @@ #if defined(PS2) #include #include -#include #endif #if defined(__PSL1GHT__) @@ -191,7 +190,7 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) #elif defined(VITA) sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); #elif defined(PS2) - time_ticks = SDL_GetTicks()*294912; // 294,912MHZ / 1000 msecs + time_ticks = clock()*294912; // 294,912MHZ / 1000 msecs #elif defined(_3DS) time_ticks = svcGetSystemTick(); #elif defined(WIIU) @@ -241,7 +240,7 @@ retro_time_t cpu_features_get_time_usec(void) #elif defined(EMSCRIPTEN) return emscripten_get_now() * 1000; #elif defined(PS2) - return SDL_GetTicks()*1000; + return clock()*1000; #elif defined(__mips__) || defined(DJGPP) struct timeval tv; gettimeofday(&tv,NULL); diff --git a/libretro-common/rthreads/rthreads.c b/libretro-common/rthreads/rthreads.c index 7c67d9465c..930f71b05c 100644 --- a/libretro-common/rthreads/rthreads.c +++ b/libretro-common/rthreads/rthreads.c @@ -853,9 +853,9 @@ bool scond_wait_timeout(scond_t *cond, slock_t *lock, int64_t timeout_us) now.tv_sec = s; now.tv_nsec = n; #elif defined(PS2) - int tickUS = cpu_ticks()/295.0; - now.tv_sec = tickUS/1000000; - now.tv_nsec = tickUS * 1000; + int tickms = clock(); + now.tv_sec = tickms/1000; + now.tv_nsec = tickms * 1000; #elif defined(__mips__) || defined(VITA) || defined(_3DS) struct timeval tm; diff --git a/ps2/compat_ctype.c b/ps2/compat_files/compat_ctype.c similarity index 96% rename from ps2/compat_ctype.c rename to ps2/compat_files/compat_ctype.c index 4dbd400cea..83e80394f7 100644 --- a/ps2/compat_ctype.c +++ b/ps2/compat_files/compat_ctype.c @@ -20,7 +20,13 @@ #define ULLONG_MAX UINT64_C(0xffffffffffffffff) -/* Do not link from libc */ +/* All the functions included in this file either could be: + - Because the PS2SDK doesn't contains this specific functionality + - Because the PS2SDK implementation is wrong + + Overrriding these methods here, make that the RetroArch will execute this code + rather than the code in the linked libraries + */ int islower(int c) { diff --git a/ps2/compat_files/time.c b/ps2/compat_files/time.c new file mode 100755 index 0000000000..328fac7522 --- /dev/null +++ b/ps2/compat_files/time.c @@ -0,0 +1,108 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2019 - Francisco Javier Trujillo Mata - fjtrujy + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch 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. + * * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +/* This file improve the content of the original time.c file that belong to the PS2SDK. +The original time.c contains 4 non-static methods + +void _ps2sdk_time_init(void); +void _ps2sdk_time_deinit(void); +clock_t clock(void); +time_t time(time_t *t); + +So we need to duplicate all the method because this way the compiler will avoid to import +the code that belong to the PS2SDK */ + +#include +#include +#include +#include +#include +#include + +#define STARTING_YEAR 2000 +#define MIN_SUPPORTED_YEAR 1970 +#define MAX_SUPPORTED_YEAR 2108 +#define SECS_MIN 60L +#define MINS_HOUR 60L +#define HOURS_DAY 24L +#define DAYS_YEAR 365L +#define DEC(x) (10*(x/16)+(x%16)) +int _days[] = {-1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364}; + +static time_t _gmtotime_t ( + int yr, /* 0 based */ + int mo, /* 1 based */ + int dy, /* 1 based */ + int hr, + int mn, + int sc + ) +{ + int passed_years; + long passed_days; + long passed_seconds_current_day; + time_t seconds_from_1970 = -1; + + if ((yr >= MIN_SUPPORTED_YEAR) || (yr <= MAX_SUPPORTED_YEAR)) { + passed_years = (long)yr - MIN_SUPPORTED_YEAR; /* Years after 1970 */ + /* Calculate days for these years */ + passed_days = passed_years * DAYS_YEAR; + passed_days += (passed_years >> 2) * (DAYS_YEAR + 1); /* passed leap years */ + passed_days += dy + _days[mo - 1]; /* passed days in the year */ + if ( !(yr & 3) && (mo > 2) ) { + passed_days++; /* if current year, is a leap year */ + } + passed_seconds_current_day = (((hr * MINS_HOUR) + mn) * SECS_MIN) + sc; + seconds_from_1970 = (passed_days * HOURS_DAY * MINS_HOUR * SECS_MIN) + passed_seconds_current_day; + } + + return seconds_from_1970; +} + +/* Protected methods in libc */ +void _ps2sdk_time_init(void) +{ + SDL_Init(SDL_INIT_TIMER); +} + +/* Protected methods in libc */ +void _ps2sdk_time_deinit(void) +{ + SDL_QuitSubSystem(SDL_INIT_TIMER); +} + +clock_t clock(void) +{ + return SDL_GetTicks(); +} + +time_t time(time_t *t) { + time_t tim; + sceCdCLOCK clocktime; /* defined in libcdvd.h */ + + sceCdReadClock(&clocktime); /* libcdvd.a */ + configConvertToLocalTime(&clocktime); + + tim = _gmtotime_t (DEC(clocktime.year)+ STARTING_YEAR, + DEC(clocktime.month), + DEC(clocktime.day), + DEC(clocktime.hour), + DEC(clocktime.minute), + DEC(clocktime.second)); + + if(t) + *t = tim; + + return tim; +} diff --git a/ps2/include/stdint.h b/ps2/include/stdint.h index e1db22e6da..cc2582c1f3 100644 --- a/ps2/include/stdint.h +++ b/ps2/include/stdint.h @@ -27,7 +27,7 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long uint64_t; -#define STDIN_FILENO 0 /* standard input file descriptor */ +#define STDIN_FILENO 0 /* standard input file descriptor */ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */