This commit is contained in:
twinaphex 2020-06-04 23:47:40 +02:00
parent 61c1b24bd9
commit 16a1caa26a
13 changed files with 314 additions and 8 deletions

View File

@ -32,6 +32,7 @@
#include <file/file_path.h>
#include <retro_assert.h>
#include <string/stdstring.h>
#include <time/rtime.h>
/* TODO: There are probably some unnecessary things on this huge include list now but I'm too afraid to touch it */
#ifdef __APPLE__
@ -482,11 +483,13 @@ void fill_pathname_parent_dir(char *out_dir,
size_t fill_dated_filename(char *out_filename,
const char *ext, size_t size)
{
time_t cur_time = time(NULL);
const struct tm* tm_ = localtime(&cur_time);
time_t cur_time = time(NULL);
struct tm tm_;
rtime_localtime(&cur_time, &tm_);
strftime(out_filename, size,
"RetroArch-%m%d-%H%M%S", tm_);
"RetroArch-%m%d-%H%M%S", &tm_);
return strlcat(out_filename, ext, size);
}
@ -507,19 +510,21 @@ void fill_str_dated_filename(char *out_filename,
const char *in_str, const char *ext, size_t size)
{
char format[256];
time_t cur_time = time(NULL);
const struct tm* tm_ = localtime(&cur_time);
struct tm tm_;
time_t cur_time = time(NULL);
format[0] = '\0';
format[0] = '\0';
rtime_localtime(&cur_time, &tm_);
if (string_is_empty(ext))
{
strftime(format, sizeof(format), "-%y%m%d-%H%M%S", tm_);
strftime(format, sizeof(format), "-%y%m%d-%H%M%S", &tm_);
fill_pathname_noext(out_filename, in_str, format, size);
}
else
{
strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", tm_);
strftime(format, sizeof(format), "-%y%m%d-%H%M%S.", &tm_);
fill_pathname_join_concat_noext(out_filename,
in_str, format, ext,

View File

@ -279,6 +279,9 @@ enum retro_language
RETRO_LANGUAGE_GREEK = 17,
RETRO_LANGUAGE_TURKISH = 18,
RETRO_LANGUAGE_SLOVAK = 19,
RETRO_LANGUAGE_PERSIAN = 20,
RETRO_LANGUAGE_HEBREW = 21,
RETRO_LANGUAGE_ASTURIAN = 22,
RETRO_LANGUAGE_LAST,
/* Ensure sizeof(enum) == sizeof(int) */

View File

@ -108,6 +108,8 @@ uint32_t intfstream_get_frame_size(intfstream_internal_t *intf);
bool intfstream_is_compressed(intfstream_internal_t *intf);
bool intfstream_get_crc(intfstream_internal_t *intf, uint32_t *crc);
intfstream_t *intfstream_open_file(const char *path,
unsigned mode, unsigned hints);

48
include/time/rtime.h Normal file
View File

@ -0,0 +1,48 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rtime.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_RTIME_H__
#define __LIBRETRO_SDK_RTIME_H__
#include <retro_common_api.h>
#include <stdint.h>
#include <stddef.h>
#include <time.h>
RETRO_BEGIN_DECLS
/* TODO/FIXME: Move all generic time handling functions
* to this file */
/* Must be called before using rtime_localtime() */
void rtime_init(void);
/* Must be called upon program termination */
void rtime_deinit(void);
/* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result);
RETRO_END_DECLS
#endif

113
libco/psp2.c Normal file
View File

@ -0,0 +1,113 @@
/*
libco.arm (2015-06-18)
license: public domain
*/
#define LIBCO_C
#include "libco.h"
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <psp2/kernel/sysmem.h>
#include <stdio.h>
#include <string.h>
#define FOUR_KB_ALIGN(x) align(x, 12)
#define MB_ALIGN(x) align(x, 20)
#ifdef __cplusplus
extern "C" {
#endif
static inline int align(int x, int n)
{
return (((x >> n) + 1) << n);
}
static thread_local unsigned long co_active_buffer[64];
static thread_local cothread_t co_active_handle = 0;
static void(*co_swap)(cothread_t, cothread_t) = 0;
static int block;
static uint32_t co_swap_function[] = {
0xe8a16ff0, /* stmia r1!, {r4-r11,sp,lr} */
0xe8b0aff0, /* ldmia r0!, {r4-r11,sp,pc} */
0xe12fff1e, /* bx lr */
};
static void co_init(void)
{
int ret;
void *base;
block = sceKernelAllocMemBlockForVM("libco",
MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
if (block < 0)
return;
/* get base address */
ret = sceKernelGetMemBlockBase(block, &base);
if (ret < 0)
return;
/* set domain to be writable by user */
ret = sceKernelOpenVMDomain();
if (ret < 0)
return;
memcpy(base, co_swap_function, sizeof co_swap_function);
/* set domain back to read-only */
ret = sceKernelCloseVMDomain();
if (ret < 0)
return;
/* flush icache */
ret = sceKernelSyncVMDomain(block, base,
MB_ALIGN(FOUR_KB_ALIGN(sizeof co_swap_function)));
if (ret < 0)
return;
co_swap = (void(*)(cothread_t, cothread_t))base;
}
cothread_t co_active(void)
{
if (!co_active_handle) co_active_handle = &co_active_buffer;
return co_active_handle;
}
cothread_t co_create(unsigned int size, void(*entrypoint)(void))
{
unsigned long* handle = 0;
if (!co_swap)
co_init();
if (!co_active_handle) co_active_handle = &co_active_buffer;
size += 256;
size &= ~15;
if ((handle = (unsigned long*)malloc(size)))
{
unsigned long* p = (unsigned long*)((unsigned char*)handle + size);
handle[8] = (unsigned long)p;
handle[9] = (unsigned long)entrypoint;
}
return handle;
}
void co_delete(cothread_t handle)
{
free(handle);
sceKernelFreeMemBlock(block);
}
void co_switch(cothread_t handle)
{
cothread_t co_previous_handle = co_active_handle;
co_swap(co_active_handle = handle, co_previous_handle);
}
#ifdef __cplusplus
}
#endif

View File

@ -117,6 +117,10 @@ struct retro_core_option_definition *option_defs_intl[RETRO_LANGUAGE_LAST] = {
NULL, /* RETRO_LANGUAGE_GREEK */
NULL, /* RETRO_LANGUAGE_TURKISH */
NULL, /* RETRO_LANGUAGE_SLOVAK */
NULL, /* RETRO_LANGUAGE_PERSIAN */
NULL, /* RETRO_LANGUAGE_HEBREW */
NULL, /* RETRO_LANGUAGE_ASTURIAN */
};
#endif

View File

@ -75,6 +75,12 @@ extern "C" {
/* RETRO_LANGUAGE_SLOVAK */
/* RETRO_LANGUAGE_PERSIAN */
/* RETRO_LANGUAGE_HEBREW */
/* RETRO_LANGUAGE_ASTURIAN */
#ifdef __cplusplus
}
#endif

View File

@ -132,6 +132,9 @@ struct retro_core_option_definition *option_defs_intl[RETRO_LANGUAGE_LAST] = {
NULL, /* RETRO_LANGUAGE_GREEK */
NULL, /* RETRO_LANGUAGE_TURKISH */
NULL, /* RETRO_LANGUAGE_SLOVAK */
NULL, /* RETRO_LANGUAGE_PERSIAN */
NULL, /* RETRO_LANGUAGE_HEBREW */
NULL, /* RETRO_LANGUAGE_ASTURIAN */
};
#endif

View File

@ -75,6 +75,12 @@ extern "C" {
/* RETRO_LANGUAGE_SLOVAK */
/* RETRO_LANGUAGE_PERSIAN */
/* RETRO_LANGUAGE_HEBREW */
/* RETRO_LANGUAGE_ASTURIAN */
#ifdef __cplusplus
}
#endif

View File

@ -117,6 +117,9 @@ struct retro_core_option_definition *option_defs_intl[RETRO_LANGUAGE_LAST] = {
NULL, /* RETRO_LANGUAGE_GREEK */
NULL, /* RETRO_LANGUAGE_TURKISH */
NULL, /* RETRO_LANGUAGE_SLOVAK */
NULL, /* RETRO_LANGUAGE_PERSIAN */
NULL, /* RETRO_LANGUAGE_HEBREW */
NULL, /* RETRO_LANGUAGE_ASTURIAN */
};
#endif

View File

@ -110,6 +110,12 @@ struct retro_core_option_definition option_defs_fr[] = {
/* RETRO_LANGUAGE_SLOVAK */
/* RETRO_LANGUAGE_PERSIAN */
/* RETRO_LANGUAGE_HEBREW */
/* RETRO_LANGUAGE_ASTURIAN */
#ifdef __cplusplus
}
#endif

View File

@ -31,6 +31,7 @@
#if defined(HAVE_ZLIB)
#include <streams/rzip_stream.h>
#endif
#include <encodings/crc32.h>
struct intfstream_internal
{
@ -615,6 +616,32 @@ bool intfstream_is_compressed(intfstream_internal_t *intf)
return false;
}
bool intfstream_get_crc(intfstream_internal_t *intf, uint32_t *crc)
{
int64_t data_read = 0;
uint32_t accumulator = 0;
uint8_t buffer[4096];
if (!intf || !crc)
return false;
/* Ensure we start at the beginning of the file */
intfstream_rewind(intf);
while ((data_read = intfstream_read(intf, buffer, sizeof(buffer))) > 0)
accumulator = encoding_crc32(accumulator, buffer, (size_t)data_read);
if (data_read < 0)
return false;
*crc = accumulator;
/* Reset file to the beginning */
intfstream_rewind(intf);
return true;
}
intfstream_t* intfstream_open_file(const char *path,
unsigned mode, unsigned hints)
{

80
time/rtime.c Normal file
View File

@ -0,0 +1,80 @@
/* Copyright (C) 2010-2020 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (rtime.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_THREADS
#include <rthreads/rthreads.h>
#include <retro_assert.h>
#include <stdlib.h>
#endif
#include <string.h>
#include <time/rtime.h>
#ifdef HAVE_THREADS
slock_t *rtime_localtime_lock = NULL;
#endif
/* Must be called before using rtime_localtime() */
void rtime_init(void)
{
rtime_deinit();
#ifdef HAVE_THREADS
if (!rtime_localtime_lock)
rtime_localtime_lock = slock_new();
retro_assert(rtime_localtime_lock);
#endif
}
/* Must be called upon program termination */
void rtime_deinit(void)
{
#ifdef HAVE_THREADS
if (rtime_localtime_lock)
{
slock_free(rtime_localtime_lock);
rtime_localtime_lock = NULL;
}
#endif
}
/* Thread-safe wrapper for localtime() */
struct tm *rtime_localtime(const time_t *timep, struct tm *result)
{
struct tm *time_info = NULL;
/* Lock mutex */
#ifdef HAVE_THREADS
slock_lock(rtime_localtime_lock);
#endif
time_info = localtime(timep);
if (time_info)
memcpy(result, time_info, sizeof(struct tm));
/* Unlock mutex */
#ifdef HAVE_THREADS
slock_unlock(rtime_localtime_lock);
#endif
return result;
}