diff --git a/cmake/modules/Findjerryscript.cmake b/cmake/modules/Findjerryscript.cmake index eadf9309..a06ef212 100644 --- a/cmake/modules/Findjerryscript.cmake +++ b/cmake/modules/Findjerryscript.cmake @@ -8,6 +8,7 @@ set(JERRY_CMDLINE OFF CACHE BOOL "" FORCE) set(JERRY_EXT ON CACHE BOOL "" FORCE) set(JERRY_DEBUGGER OFF CACHE BOOL "" FORCE) set(JERRY_BUILTIN_DATE OFF CACHE BOOL "" FORCE) +set(ENABLE_LTO OFF CACHE BOOL "" FORCE) # Fetch Jerry include(FetchContent) @@ -34,12 +35,38 @@ elseif(TARGET jerry-ext) set(JERRY_EXT_TARGET jerry-ext) endif() -if(TARGET jerryscript-port) +if(TARGET jerryscript-port-default) + set(JERRY_PORT_TARGET jerryscript-port-default) +elseif(TARGET jerry-port-default) + set(JERRY_PORT_TARGET jerry-port-default) +elseif(TARGET jerryscript-port) set(JERRY_PORT_TARGET jerryscript-port) elseif(TARGET jerry-port) set(JERRY_PORT_TARGET jerry-port) endif() +if(NOT JERRY_CORE_TARGET) + message(FATAL_ERROR "JerryScript core target not found") +endif() + +if(NOT JERRY_EXT_TARGET) + message(FATAL_ERROR "JerryScript ext target not found") +endif() + +if(NOT JERRY_PORT_TARGET) + message(FATAL_ERROR "JerryScript port target not found") +endif() + +foreach(tgt IN ITEMS + ${JERRY_CORE_TARGET} + ${JERRY_EXT_TARGET} + ${JERRY_PORT_TARGET} +) + if(TARGET ${tgt}) + set_property(TARGET ${tgt} PROPERTY INTERPROCEDURAL_OPTIMIZATION OFF) + endif() +endforeach() + # Export include dirs through the targets target_include_directories(${JERRY_CORE_TARGET} INTERFACE ${jerryscript_SOURCE_DIR}/jerry-core/include diff --git a/cmake/targets/psp.cmake b/cmake/targets/psp.cmake index be3e853b..ca4bd937 100644 --- a/cmake/targets/psp.cmake +++ b/cmake/targets/psp.cmake @@ -1,6 +1,19 @@ +# Fixes some problems building JerryScript +set(CMAKE_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE) +set(CMAKE_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" CACHE FILEPATH "" FORCE) +set(CMAKE_C_COMPILER_AR "$ENV{PSPDEV}/bin/psp-ar" CACHE FILEPATH "" FORCE) +set(CMAKE_C_COMPILER_RANLIB "$ENV{PSPDEV}/bin/psp-ranlib" CACHE FILEPATH "" FORCE) +set(CMAKE_C_ARCHIVE_CREATE "$ENV{PSPDEV}/bin/psp-ar qc ") +set(CMAKE_C_ARCHIVE_APPEND "$ENV{PSPDEV}/bin/psp-ar q ") +set(CMAKE_C_ARCHIVE_FINISH "$ENV{PSPDEV}/bin/psp-ranlib ") +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "" FORCE) +set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_C OFF CACHE BOOL "" FORCE) +set(JERRY_LTO OFF CACHE BOOL "" FORCE) + +find_package(jerryscript REQUIRED) find_package(SDL2 REQUIRED) find_package(OpenGL REQUIRED) -target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC +target_link_libraries(${DUSK_BINARY_TARGET_NAME} PUBLIC ${SDL2_LIBRARIES} SDL2 pthread @@ -29,13 +42,17 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC pspnet_apctl psphttp pspssl + + jerryscript::core + jerryscript::ext + jerryscript::port ) -target_include_directories(${DUSK_LIBRARY_TARGET_NAME} PRIVATE +target_include_directories(${DUSK_BINARY_TARGET_NAME} PRIVATE ${SDL2_INCLUDE_DIRS} ) -target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC +target_compile_definitions(${DUSK_BINARY_TARGET_NAME} PUBLIC DUSK_SDL2 DUSK_OPENGL DUSK_PSP diff --git a/src/dusk/CMakeLists.txt b/src/dusk/CMakeLists.txt index 057b1f01..b214e129 100644 --- a/src/dusk/CMakeLists.txt +++ b/src/dusk/CMakeLists.txt @@ -48,7 +48,7 @@ endif() if(NOT jerryscript_FOUND) find_package(jerryscript REQUIRED) - target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC + target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PRIVATE jerryscript::core jerryscript::ext jerryscript::port diff --git a/src/dusk/time/time.c b/src/dusk/time/time.c index 8cbca738..1e73348f 100644 --- a/src/dusk/time/time.c +++ b/src/dusk/time/time.c @@ -53,7 +53,7 @@ void timeUpdate(void) { dusktimeepoch_t epoch = timeGetEpoch(); char_t buffer[256]; timeEpochFormat(epoch, "%Y-%m-%d %H:%M:%S", buffer, sizeof(buffer)); - consolePrint("Real Time: %s", buffer); + // consolePrint("Real Time: %s", buffer); } dusktimeepoch_t timeGetEpoch(void) { diff --git a/src/dusk/time/time.h b/src/dusk/time/time.h index ee5575af..187c9280 100644 --- a/src/dusk/time/time.h +++ b/src/dusk/time/time.h @@ -7,14 +7,13 @@ #pragma once #include "timeepoch.h" +#include "time/timeplatform.h" #ifndef DUSK_TIME_STEP #define DUSK_TIME_STEP (16.0f / 1000.0f) #endif #ifdef DUSK_TIME_DYNAMIC - #include "time/timeplatform.h" - #ifndef timeTickPlatform #error "DUSK_TIME_DYNAMIC needs tick method defined" #endif diff --git a/src/duskdolphin/CMakeLists.txt b/src/duskdolphin/CMakeLists.txt index cded9291..78be2119 100644 --- a/src/duskdolphin/CMakeLists.txt +++ b/src/duskdolphin/CMakeLists.txt @@ -20,4 +20,5 @@ add_subdirectory(log) add_subdirectory(display) add_subdirectory(input) add_subdirectory(network) -add_subdirectory(system) \ No newline at end of file +add_subdirectory(system) +add_subdirectory(time) \ No newline at end of file diff --git a/src/duskdolphin/time/CMakeLists.txt b/src/duskdolphin/time/CMakeLists.txt new file mode 100644 index 00000000..8a69ff22 --- /dev/null +++ b/src/duskdolphin/time/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + timedolphin.c +) diff --git a/src/duskdolphin/time/timedolphin.c b/src/duskdolphin/time/timedolphin.c new file mode 100644 index 00000000..1d053693 --- /dev/null +++ b/src/duskdolphin/time/timedolphin.c @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "time/timedolphin.h" + +double_t timeGetRealDolphin(void) { + // "Returns time in ticks since 2000" + u64 timeInMillis = PPCTicksToMs(SYS_Time()); + double_t timeSeconds = (double_t)timeInMillis / 1000.0; + + // Time to adjust time from 2000 to 1970, in seconds + double_t timeOffset = 946684800.0; + + timeSeconds += timeOffset; + return timeSeconds; +} + +double_t timeGetRealTimeZoneDolphin(void) { + return 0.0; +} \ No newline at end of file diff --git a/src/duskdolphin/time/timedolphin.h b/src/duskdolphin/time/timedolphin.h new file mode 100644 index 00000000..1fde9079 --- /dev/null +++ b/src/duskdolphin/time/timedolphin.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +/** + * Returns the real current time, in seconds since January 1, 1970. + * + * @return The real current time, in seconds since January 1, 1970. + */ +double_t timeGetRealDolphin(void); + +/** + * Returns the real time zone offset in seconds from UTC. + * + * @return The real time zone offset in seconds from UTC. + */ +double_t timeGetRealTimeZoneDolphin(void); \ No newline at end of file diff --git a/src/duskdolphin/time/timeplatform.h b/src/duskdolphin/time/timeplatform.h new file mode 100644 index 00000000..d5ad4939 --- /dev/null +++ b/src/duskdolphin/time/timeplatform.h @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "time/timedolphin.h" + +#define timeGetRealPlatform timeGetRealDolphin +#define timeGetRealTimeZonePlatform timeGetRealTimeZoneDolphin \ No newline at end of file diff --git a/src/duskpsp/CMakeLists.txt b/src/duskpsp/CMakeLists.txt index 95f5ed65..1bdee020 100644 --- a/src/duskpsp/CMakeLists.txt +++ b/src/duskpsp/CMakeLists.txt @@ -19,4 +19,5 @@ add_subdirectory(asset) add_subdirectory(input) add_subdirectory(log) add_subdirectory(network) -add_subdirectory(system) \ No newline at end of file +add_subdirectory(system) +add_subdirectory(time) \ No newline at end of file diff --git a/src/duskpsp/time/CMakeLists.txt b/src/duskpsp/time/CMakeLists.txt new file mode 100644 index 00000000..b450020d --- /dev/null +++ b/src/duskpsp/time/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2026 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +target_sources(${DUSK_LIBRARY_TARGET_NAME} + PUBLIC + timepsp.c +) diff --git a/src/duskpsp/time/timeplatform.h b/src/duskpsp/time/timeplatform.h new file mode 100644 index 00000000..cecd40e3 --- /dev/null +++ b/src/duskpsp/time/timeplatform.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "time/timesdl2.h" +#include "time/timepsp.h" + +#define timeTickPlatform timeTickSDL2 +#define timeGetDeltaPlatform timeGetDeltaSDL2 +#define timeGetRealPlatform timeGetRealPSP +#define timeGetRealTimeZonePlatform timeGetRealTimeZonePSP \ No newline at end of file diff --git a/src/duskpsp/time/timepsp.c b/src/duskpsp/time/timepsp.c new file mode 100644 index 00000000..04045fbc --- /dev/null +++ b/src/duskpsp/time/timepsp.c @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "time/timepsp.h" +#include +#include +#include + +double_t timeGetRealPSP(void) { + u64 utc_ticks = 0; + + if(sceRtcGetCurrentTick(&utc_ticks) < 0) return 0.0; + + /* + PSP RTC ticks are microseconds. + Return seconds since 1970-01-01 UTC. + */ + return (double_t)utc_ticks / 1000000.0; +} + +double_t timeGetRealTimeZonePSP(void) { + u64 utc_ticks = 0; + u64 local_ticks = 0; + + if(sceRtcGetCurrentTick(&utc_ticks) < 0) return 0.0; + if(sceRtcConvertUtcToLocalTime(&utc_ticks, &local_ticks) < 0) return 0.0; + + /* + Return timezone offset in hours. + Example: + UTC-6 => -6.0 + UTC+2 => 2.0 + */ + int64_t offset_us = (int64_t)local_ticks - (int64_t)utc_ticks; + return (double_t)offset_us / (1000000.0 * 60.0 * 60.0); +} \ No newline at end of file diff --git a/src/duskpsp/time/timepsp.h b/src/duskpsp/time/timepsp.h new file mode 100644 index 00000000..a0f02316 --- /dev/null +++ b/src/duskpsp/time/timepsp.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2026 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dusk.h" + +/** + * Returns the real current time, in seconds since January 1, 1970. + * + * @return The real current time, in seconds since January 1, 1970. + */ +double_t timeGetRealPSP(void); + +/** + * Returns the real time zone offset in seconds from UTC. + * + * @return The real time zone offset in seconds from UTC. + */ +double_t timeGetRealTimeZonePSP(void); \ No newline at end of file