From 80fcb83503e8039a681497e39e58117c4cd23eb6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 19 May 2021 16:45:56 +0200 Subject: [PATCH] Resync --- Makefile.test | 58 +++ features/features_cpu.c | 27 +- file/archive_file_7z.c | 95 ++--- file/config_file.c | 134 ++++-- formats/libchdr/libchdr_chd.c | 8 +- formats/libchdr/libchdr_lzma.c | 2 +- formats/png/rpng.c | 5 +- include/array/rhmap.h | 284 +++++++++++++ include/defines/cocoa_defines.h | 73 ++++ include/defines/d3d_defines.h | 92 +++++ include/defines/gx_defines.h | 96 +++++ include/defines/ps3_defines.h | 704 ++++++++++++++++++++++++++++++++ include/defines/psp_defines.h | 145 +++++++ include/file/config_file.h | 1 + include/libretro.h | 51 +++ include/lists/linked_list.h | 298 ++++++++++++++ include/queues/generic_queue.h | 208 ++++++++++ streams/file_stream.c | 3 +- vfs/vfs_implementation.c | 3 + 19 files changed, 2202 insertions(+), 85 deletions(-) create mode 100644 Makefile.test create mode 100644 include/array/rhmap.h create mode 100644 include/defines/cocoa_defines.h create mode 100644 include/defines/d3d_defines.h create mode 100644 include/defines/gx_defines.h create mode 100644 include/defines/ps3_defines.h create mode 100644 include/defines/psp_defines.h create mode 100644 include/lists/linked_list.h create mode 100644 include/queues/generic_queue.h diff --git a/Makefile.test b/Makefile.test new file mode 100644 index 0000000..4e1deed --- /dev/null +++ b/Makefile.test @@ -0,0 +1,58 @@ + +OBJDIR = ../obj-unix + +TEST_UNIT_CFLAGS = $(CFLAGS) -Iinclude $(LDFLAGS) -lcheck $(LIBCHECK_CFLAGS) -Werror -Wdeclaration-after-statement -fsanitize=address -fsanitize=undefined -ftest-coverage -fprofile-arcs -ggdb + +TEST_GENERIC_QUEUE = test/queues/test_generic_queue +TEST_GENERIC_QUEUE_SRC = test/queues/test_generic_queue.c queues/generic_queue.c + +TEST_LINKED_LIST = test/lists/test_linked_list +TEST_LINKED_LIST_SRC = test/lists/test_linked_list.c lists/linked_list.c + +TEST_STDSTRING = test/string/test_stdstring +TEST_STDSTRING_SRC = test/string/test_stdstring.c string/stdstring.c encodings/encoding_utf.c \ + compat/compat_strl.c + +TEST_UTILS = test/utils/test_utils +TEST_UTILS_SRC = test/utils/test_utils.c utils/md5.c encodings/encoding_crc32.c \ + streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \ + compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c + +TEST_HASH = test/hash/test_hash +TEST_HASH_SRC = test/hash/test_hash.c hash/lrc_hash.c \ + streams/file_stream.c vfs/vfs_implementation.c file/file_path.c \ + compat/compat_strl.c time/rtime.c string/stdstring.c encodings/encoding_utf.c + +all: + # Build and execute tests in order, to avoid coverage file collision + # string + $(CC) $(TEST_UNIT_CFLAGS) $(TEST_STDSTRING_SRC) -o $(TEST_STDSTRING) + $(TEST_STDSTRING) + lcov -c -d . -o `dirname $(TEST_STDSTRING)`/coverage.info + # utils + $(CC) $(TEST_UNIT_CFLAGS) $(TEST_UTILS_SRC) -o $(TEST_UTILS) + $(TEST_UTILS) + lcov -c -d . -o `dirname $(TEST_UTILS)`/coverage.info + # utils + $(CC) $(TEST_UNIT_CFLAGS) $(TEST_HASH_SRC) -o $(TEST_HASH) + $(TEST_HASH) + lcov -c -d . -o `dirname $(TEST_HASH)`/coverage.info + # list + $(CC) $(TEST_UNIT_CFLAGS) $(TEST_LINKED_LIST_SRC) -o $(TEST_LINKED_LIST) + $(TEST_LINKED_LIST) + lcov -c -d . -o `dirname $(TEST_LINKED_LIST)`/coverage.info + # queue + $(CC) $(TEST_UNIT_CFLAGS) $(TEST_GENERIC_QUEUE_SRC) -o $(TEST_GENERIC_QUEUE) + $(TEST_GENERIC_QUEUE) + lcov -c -d . -o `dirname $(TEST_GENERIC_QUEUE)`/coverage.info + + lcov -o test/coverage.info \ + -a test/utils/coverage.info \ + -a test/string/coverage.info \ + -a test/lists/coverage.info \ + -a test/queues/coverage.info + genhtml -o test/coverage/ test/coverage.info + +clean: + rm -f *.gcda *.gcno + diff --git a/features/features_cpu.c b/features/features_cpu.c index adcbe13..9bb11a2 100644 --- a/features/features_cpu.c +++ b/features/features_cpu.c @@ -177,7 +177,7 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) time_ticks = gettime(); #elif !defined(__MACH__) && (defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) || defined(__PSL1GHT__) || defined(__PPC64__) || defined(__powerpc64__)) time_ticks = __mftb(); -#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(__QNX__) || defined(ANDROID) || defined(__MACH__) +#elif (defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0) || defined(__QNX__) || defined(ANDROID) struct timespec tv = {0}; if (ra_clock_gettime(CLOCK_MONOTONIC, &tv) == 0) time_ticks = (retro_perf_tick_t)tv.tv_sec * 1000000000 + @@ -191,6 +191,8 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) time_ticks = (retro_perf_tick_t)a | ((retro_perf_tick_t)d << 32); #elif defined(__ARM_ARCH_6__) __asm__ volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(time_ticks) ); +#elif defined(__aarch64__) + __asm__ volatile( "mrs %0, cntvct_el0" : "=r"(time_ticks) ); #elif defined(PSP) || defined(VITA) time_ticks = sceKernelGetSystemTimeWide(); #elif defined(PS2) @@ -600,18 +602,20 @@ uint64_t cpu_features_get(void) #endif #if defined(__MACH__) size_t len = sizeof(size_t); + + if (sysctlbyname("hw.optional.floatingpoint", NULL, &len, NULL, 0) == 0) + { + cpu |= RETRO_SIMD_CMOV; + } + +#if defined(CPU_X86) + len = sizeof(size_t); if (sysctlbyname("hw.optional.mmx", NULL, &len, NULL, 0) == 0) { cpu |= RETRO_SIMD_MMX; cpu |= RETRO_SIMD_MMXEXT; } - len = sizeof(size_t); - if (sysctlbyname("hw.optional.floatingpoint", NULL, &len, NULL, 0) == 0) - { - cpu |= RETRO_SIMD_CMOV; - } - len = sizeof(size_t); if (sysctlbyname("hw.optional.sse", NULL, &len, NULL, 0) == 0) cpu |= RETRO_SIMD_SSE; @@ -652,10 +656,19 @@ uint64_t cpu_features_get(void) if (sysctlbyname("hw.optional.altivec", NULL, &len, NULL, 0) == 0) cpu |= RETRO_SIMD_VMX; +#else len = sizeof(size_t); if (sysctlbyname("hw.optional.neon", NULL, &len, NULL, 0) == 0) cpu |= RETRO_SIMD_NEON; + len = sizeof(size_t); + if (sysctlbyname("hw.optional.neon_fp16", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_VFPV3; + + len = sizeof(size_t); + if (sysctlbyname("hw.optional.neon_hpfp", NULL, &len, NULL, 0) == 0) + cpu |= RETRO_SIMD_VFPV4; +#endif #elif defined(_XBOX1) cpu |= RETRO_SIMD_MMX; cpu |= RETRO_SIMD_SSE; diff --git a/file/archive_file_7z.c b/file/archive_file_7z.c index 2179e32..b9a82c1 100644 --- a/file/archive_file_7z.c +++ b/file/archive_file_7z.c @@ -38,6 +38,7 @@ #define SEVENZIP_MAGIC "7z\xBC\xAF\x27\x1C" #define SEVENZIP_MAGIC_LEN 6 +#define SEVENZIP_LOOKTOREAD_BUF_SIZE (1 << 14) /* Assume W-functions do not work below Win2K and Xbox platforms */ #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX) @@ -50,25 +51,25 @@ struct sevenzip_context_t { uint8_t *output; CFileInStream archiveStream; - CLookToRead lookStream; + CLookToRead2 lookStream; ISzAlloc allocImp; ISzAlloc allocTempImp; CSzArEx db; size_t temp_size; - uint32_t block_index; uint32_t parse_index; uint32_t decompress_index; uint32_t packIndex; + UInt32 block_index; }; -static void *sevenzip_stream_alloc_impl(void *p, size_t size) +static void *sevenzip_stream_alloc_impl(ISzAllocPtr p, size_t size) { if (size == 0) return 0; return malloc(size); } -static void sevenzip_stream_free_impl(void *p, void *address) +static void sevenzip_stream_free_impl(ISzAllocPtr p, void *address) { (void)p; @@ -76,7 +77,7 @@ static void sevenzip_stream_free_impl(void *p, void *address) free(address); } -static void *sevenzip_stream_alloc_tmp_impl(void *p, size_t size) +static void *sevenzip_stream_alloc_tmp_impl(ISzAllocPtr p, size_t size) { (void)p; if (size == 0) @@ -98,6 +99,12 @@ static void* sevenzip_stream_new(void) sevenzip_context->block_index = 0xFFFFFFFF; sevenzip_context->output = NULL; + sevenzip_context->lookStream.bufSize = SEVENZIP_LOOKTOREAD_BUF_SIZE * sizeof(Byte); + sevenzip_context->lookStream.buf = (Byte*)malloc(sevenzip_context->lookStream.bufSize); + + if (!sevenzip_context->lookStream.buf) + sevenzip_context->lookStream.bufSize = 0; + return sevenzip_context; } @@ -117,6 +124,9 @@ static void sevenzip_parse_file_free(void *context) SzArEx_Free(&sevenzip_context->db, &sevenzip_context->allocImp); File_Close(&sevenzip_context->archiveStream.file); + if (sevenzip_context->lookStream.buf) + free(sevenzip_context->lookStream.buf); + free(sevenzip_context); } @@ -131,7 +141,7 @@ static int64_t sevenzip_file_read( const char *optional_outfile) { CFileInStream archiveStream; - CLookToRead lookStream; + CLookToRead2 lookStream; ISzAlloc allocImp; ISzAlloc allocTempImp; CSzArEx db; @@ -145,6 +155,12 @@ static int64_t sevenzip_file_read( allocTempImp.Alloc = sevenzip_stream_alloc_tmp_impl; allocTempImp.Free = sevenzip_stream_free_impl; + lookStream.bufSize = SEVENZIP_LOOKTOREAD_BUF_SIZE * sizeof(Byte); + lookStream.buf = (Byte*)malloc(lookStream.bufSize); + + if (!lookStream.buf) + lookStream.bufSize = 0; + #if defined(_WIN32) && defined(USE_WINDOWS_FILE) && !defined(LEGACY_WIN32) if (!string_is_empty(path)) { @@ -169,51 +185,34 @@ static int64_t sevenzip_file_read( #endif FileInStream_CreateVTable(&archiveStream); - LookToRead_CreateVTable(&lookStream, false); - lookStream.realStream = &archiveStream.s; - LookToRead_Init(&lookStream); + LookToRead2_CreateVTable(&lookStream, false); + lookStream.realStream = &archiveStream.vt; + LookToRead2_Init(&lookStream); CrcGenerateTable(); - db.db.PackSizes = NULL; - db.db.PackCRCsDefined = NULL; - db.db.PackCRCs = NULL; - db.db.Folders = NULL; - db.db.Files = NULL; - db.db.NumPackStreams = 0; - db.db.NumFolders = 0; - db.db.NumFiles = 0; - db.startPosAfterHeader = 0; - db.dataPos = 0; - db.FolderStartPackStreamIndex = NULL; - db.PackStreamStartPositions = NULL; - db.FolderStartFileIndex = NULL; - db.FileIndexToFolderIndexMap = NULL; - db.FileNameOffsets = NULL; - db.FileNames.data = NULL; - db.FileNames.size = 0; + memset(&db, 0, sizeof(db)); SzArEx_Init(&db); - if (SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp) == SZ_OK) + if (SzArEx_Open(&db, &lookStream.vt, &allocImp, &allocTempImp) == SZ_OK) { uint32_t i; bool file_found = false; uint16_t *temp = NULL; size_t temp_size = 0; - uint32_t block_index = 0xFFFFFFFF; + UInt32 block_index = 0xFFFFFFFF; SRes res = SZ_OK; - for (i = 0; i < db.db.NumFiles; i++) + for (i = 0; i < db.NumFiles; i++) { size_t len; char infile[PATH_MAX_LENGTH]; size_t offset = 0; size_t outSizeProcessed = 0; - const CSzFileItem *f = db.db.Files + i; /* We skip over everything which is not a directory. - * FIXME: Why continue then if f->IsDir is true?*/ - if (f->IsDir) + * FIXME: Why continue then if IsDir is true?*/ + if (SzArEx_IsDir(&db, i)) continue; len = SzArEx_GetFileNameUtf16(&db, i, NULL); @@ -248,7 +247,7 @@ static int64_t sevenzip_file_read( * sourceforge.net/p/sevenzip/discussion/45798/thread/6fb59aaf/ * */ file_found = true; - res = SzArEx_Extract(&db, &lookStream.s, i, &block_index, + res = SzArEx_Extract(&db, &lookStream.vt, i, &block_index, &output, &output_size, &offset, &outSizeProcessed, &allocImp, &allocTempImp); @@ -301,6 +300,9 @@ static int64_t sevenzip_file_read( SzArEx_Free(&db, &allocImp); File_Close(&archiveStream.file); + if (lookStream.buf) + free(lookStream.buf); + return outsize; } @@ -331,7 +333,7 @@ static int sevenzip_stream_decompress_data_to_file_iterate( size_t outSizeProcessed = 0; res = SzArEx_Extract(&sevenzip_context->db, - &sevenzip_context->lookStream.s, sevenzip_context->decompress_index, + &sevenzip_context->lookStream.vt, sevenzip_context->decompress_index, &sevenzip_context->block_index, &sevenzip_context->output, &output_size, &offset, &outSizeProcessed, &sevenzip_context->allocImp, &sevenzip_context->allocTempImp); @@ -388,17 +390,17 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state, #endif FileInStream_CreateVTable(&sevenzip_context->archiveStream); - LookToRead_CreateVTable(&sevenzip_context->lookStream, false); - sevenzip_context->lookStream.realStream = &sevenzip_context->archiveStream.s; - LookToRead_Init(&sevenzip_context->lookStream); + LookToRead2_CreateVTable(&sevenzip_context->lookStream, false); + sevenzip_context->lookStream.realStream = &sevenzip_context->archiveStream.vt; + LookToRead2_Init(&sevenzip_context->lookStream); CrcGenerateTable(); SzArEx_Init(&sevenzip_context->db); - if (SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.s, + if (SzArEx_Open(&sevenzip_context->db, &sevenzip_context->lookStream.vt, &sevenzip_context->allocImp, &sevenzip_context->allocTempImp) != SZ_OK) goto error; - state->step_total = sevenzip_context->db.db.NumFiles; + state->step_total = sevenzip_context->db.NumFiles; return 0; @@ -414,9 +416,7 @@ static int sevenzip_parse_file_iterate_step_internal( uint32_t *size, uint32_t *csize, uint32_t *checksum, unsigned *payback, struct archive_extract_userdata *userdata) { - const CSzFileItem *file = sevenzip_context->db.db.Files + sevenzip_context->parse_index; - - if (sevenzip_context->parse_index < sevenzip_context->db.db.NumFiles) + if (sevenzip_context->parse_index < sevenzip_context->db.NumFiles) { size_t len = SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->parse_index, NULL); @@ -424,11 +424,14 @@ static int sevenzip_parse_file_iterate_step_internal( if (sevenzip_context->packIndex < sevenzip_context->db.db.NumPackStreams) { - compressed_size = sevenzip_context->db.db.PackSizes[sevenzip_context->packIndex]; + compressed_size = sevenzip_context->db.db.PackPositions[sevenzip_context->packIndex + 1] - + sevenzip_context->db.db.PackPositions[sevenzip_context->packIndex]; + sevenzip_context->packIndex++; } - if (len < PATH_MAX_LENGTH && !file->IsDir) + if (len < PATH_MAX_LENGTH && + !SzArEx_IsDir(&sevenzip_context->db, sevenzip_context->parse_index)) { char infile[PATH_MAX_LENGTH]; SRes res = SZ_ERROR_FAIL; @@ -455,8 +458,8 @@ static int sevenzip_parse_file_iterate_step_internal( strlcpy(filename, infile, PATH_MAX_LENGTH); *cmode = 0; /* unused for 7zip */ - *checksum = file->Crc; - *size = (uint32_t)file->Size; + *checksum = sevenzip_context->db.CRCs.Vals[sevenzip_context->parse_index]; + *size = (uint32_t)SzArEx_GetFileSize(&sevenzip_context->db, sevenzip_context->parse_index); *csize = (uint32_t)compressed_size; *cdata = (uint8_t *)(size_t)sevenzip_context->parse_index; diff --git a/file/config_file.c b/file/config_file.c index 85dda16..8660cfa 100644 --- a/file/config_file.c +++ b/file/config_file.c @@ -39,6 +39,7 @@ #include #include #include +#include #define MAX_INCLUDE_DEPTH 16 @@ -273,6 +274,8 @@ static char *config_file_extract_value(char *line, bool is_value) static void config_file_add_child_list(config_file_t *parent, config_file_t *child) { struct config_entry_list *list = child->entries; + bool merge_hash_map = false; + if (parent->entries) { struct config_entry_list *head = parent->entries; @@ -286,6 +289,8 @@ static void config_file_add_child_list(config_file_t *parent, config_file_t *chi list = list->next; } head->next = child->entries; + + merge_hash_map = true; } else { @@ -298,8 +303,6 @@ static void config_file_add_child_list(config_file_t *parent, config_file_t *chi parent->entries = child->entries; } - child->entries = NULL; - /* Rebase tail. */ if (parent->entries) { @@ -312,6 +315,46 @@ static void config_file_add_child_list(config_file_t *parent, config_file_t *chi } else parent->tail = NULL; + + /* Update hash map */ + if (merge_hash_map) + { + size_t i; + size_t cap; + + /* We are merging two lists - if any child entry + * (key) is not present in the parent list, add it + * to the parent hash map */ + for (i = 0, cap = RHMAP_CAP(child->entries_map); i != cap; i++) + { + uint32_t child_hash = RHMAP_KEY(child->entries_map, i); + const char *child_key = RHMAP_KEY_STR(child->entries_map, i); + + if (child_hash && + child_key && + !RHMAP_HAS_FULL(parent->entries_map, child_hash, child_key)) + { + struct config_entry_list *entry = child->entries_map[i]; + + if (entry) + RHMAP_SET_FULL(parent->entries_map, child_hash, child_key, entry); + } + } + + /* Child entries map is no longer required, + * so free it now */ + RHMAP_FREE(child->entries_map); + } + else + { + /* If parent list was originally empty, + * take map from child list */ + RHMAP_FREE(parent->entries_map); + parent->entries_map = child->entries_map; + child->entries_map = NULL; + } + + child->entries = NULL; } static void config_file_get_realpath(char *s, size_t len, @@ -426,8 +469,21 @@ static int config_file_load_internal( conf->tail = list; - if (cb && list->key && list->value) - cb->config_file_new_entry_cb(list->key, list->value) ; + if (list->key) + { + /* Only add entry to the map if an entry + * with the specified value does not + * already exist */ + uint32_t hash = rhmap_hash_string(list->key); + + if (!RHMAP_HAS_FULL(conf->entries_map, hash, list->key)) + { + RHMAP_SET_FULL(conf->entries_map, hash, list->key, list); + + if (cb && list->value) + cb->config_file_new_entry_cb(list->key, list->value); + } + } } free(line); @@ -628,6 +684,16 @@ static int config_file_from_string_internal( conf->entries = list; conf->tail = list; + + if (list->key) + { + /* Only add entry to the map if an entry + * with the specified value does not + * already exist */ + uint32_t hash = rhmap_hash_string(list->key); + if (!RHMAP_HAS_FULL(conf->entries_map, hash, list->key)) + RHMAP_SET_FULL(conf->entries_map, hash, list->key, list); + } } if (list != conf->tail) @@ -705,6 +771,9 @@ bool config_file_deinitialize(config_file_t *conf) if (conf->path) free(conf->path); + + RHMAP_FREE(conf->entries_map); + return true; } @@ -718,9 +787,27 @@ void config_file_free(config_file_t *conf) bool config_append_file(config_file_t *conf, const char *path) { config_file_t *new_conf = config_file_new_from_path_to_string(path); + size_t i; + size_t cap; + if (!new_conf) return false; + /* Update hash map */ + for (i = 0, cap = RHMAP_CAP(new_conf->entries_map); i != cap; i++) + { + uint32_t new_hash = RHMAP_KEY(new_conf->entries_map, i); + const char *new_key = RHMAP_KEY_STR(new_conf->entries_map, i); + + if (new_hash && new_key) + { + struct config_entry_list *entry = new_conf->entries_map[i]; + + if (entry) + RHMAP_SET_FULL(conf->entries_map, new_hash, new_key, entry); + } + } + if (new_conf->tail) { new_conf->tail->next = conf->entries; @@ -818,6 +905,7 @@ void config_file_initialize(struct config_file *conf) return; conf->path = NULL; + conf->entries_map = NULL; conf->entries = NULL; conf->tail = NULL; conf->last = NULL; @@ -844,16 +932,18 @@ static struct config_entry_list *config_get_entry_internal( struct config_entry_list *entry = NULL; struct config_entry_list *previous = prev ? *prev : NULL; - for (entry = conf->entries; entry; entry = entry->next) - { - if (string_is_equal(key, entry->key)) - return entry; + entry = RHMAP_GET_STR(conf->entries_map, key); - previous = entry; - } + if (entry) + return entry; if (prev) + { + for (entry = conf->entries; entry; entry = entry->next) + previous = entry; + *prev = previous; + } return NULL; } @@ -861,16 +951,9 @@ static struct config_entry_list *config_get_entry_internal( struct config_entry_list *config_get_entry( const config_file_t *conf, const char *key) { - struct config_entry_list *entry = NULL; - for (entry = conf->entries; entry; entry = entry->next) - { - if (string_is_equal(key, entry->key)) - return entry; - } - return NULL; + return RHMAP_GET_STR(conf->entries_map, key); } - bool config_get_double(config_file_t *conf, const char *key, double *in) { const struct config_entry_list *entry = config_get_entry(conf, key); @@ -1141,6 +1224,8 @@ void config_set_string(config_file_t *conf, const char *key, const char *val) conf->entries = entry; conf->last = entry; + + RHMAP_SET_STR(conf->entries_map, entry->key, entry); } void config_unset(config_file_t *conf, const char *key) @@ -1157,6 +1242,8 @@ void config_unset(config_file_t *conf, const char *key) if (!entry) return; + (void)RHMAP_DEL_STR(conf->entries_map, entry->key); + if (entry->key) free(entry->key); @@ -1376,16 +1463,7 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort) bool config_entry_exists(config_file_t *conf, const char *entry) { - struct config_entry_list *list = conf->entries; - - while (list) - { - if (string_is_equal(entry, list->key)) - return true; - list = list->next; - } - - return false; + return (bool)RHMAP_HAS_STR(conf->entries_map, entry); } bool config_get_entry_list_head(config_file_t *conf, diff --git a/formats/libchdr/libchdr_chd.c b/formats/libchdr/libchdr_chd.c index 8574c20..603163c 100644 --- a/formats/libchdr/libchdr_chd.c +++ b/formats/libchdr/libchdr_chd.c @@ -1235,7 +1235,13 @@ chd_error chd_get_metadata(chd_file *chd, UINT32 searchtag, UINT32 searchindex, UINT32 faux_length; /* fill in the faux metadata */ - sprintf(faux_metadata, HARD_DISK_METADATA_FORMAT, chd->header.obsolete_cylinders, chd->header.obsolete_heads, chd->header.obsolete_sectors, chd->header.hunkbytes / chd->header.obsolete_hunksize); + snprintf(faux_metadata, + sizeof(faux_metadata), + HARD_DISK_METADATA_FORMAT, + chd->header.obsolete_cylinders, + chd->header.obsolete_heads, + chd->header.obsolete_sectors, + chd->header.hunkbytes / chd->header.obsolete_hunksize); faux_length = (UINT32)strlen(faux_metadata) + 1; /* copy the metadata itself */ diff --git a/formats/libchdr/libchdr_lzma.c b/formats/libchdr/libchdr_lzma.c index 0110a92..660a2f2 100644 --- a/formats/libchdr/libchdr_lzma.c +++ b/formats/libchdr/libchdr_lzma.c @@ -42,12 +42,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include diff --git a/formats/png/rpng.c b/formats/png/rpng.c index 7bdc435..a829d17 100644 --- a/formats/png/rpng.c +++ b/formats/png/rpng.c @@ -1035,7 +1035,9 @@ bool rpng_iterate_image(rpng_t *rpng) rpng->ihdr.interlace = buf[12]; if ( rpng->ihdr.width == 0 - || rpng->ihdr.height == 0) + || rpng->ihdr.height == 0 + /* ensure multiplications don't overflow and wrap around, that'd give buffer overflow crashes */ + || (uint64_t)rpng->ihdr.width*rpng->ihdr.height*sizeof(uint32_t) >= 0x80000000) return false; if (!png_process_ihdr(&rpng->ihdr)) @@ -1169,6 +1171,7 @@ error: if (rpng->process->stream) rpng->process->stream_backend->stream_free(rpng->process->stream); free(rpng->process); + rpng->process = NULL; } return IMAGE_PROCESS_ERROR; } diff --git a/include/array/rhmap.h b/include/array/rhmap.h new file mode 100644 index 0000000..20558f7 --- /dev/null +++ b/include/array/rhmap.h @@ -0,0 +1,284 @@ +/* Copyright (C) 2010-2020 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (rhmap.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_ARRAY_RHMAP_H__ +#define __LIBRETRO_SDK_ARRAY_RHMAP_H__ + +/* + * This file implements a hash map with 32-bit keys. + * Based on the implementation from the public domain Bitwise project + * by Per Vognsen - https://github.com/pervognsen/bitwise + * + * It's a super simple type safe hash map for C with no need + * to predeclare any type or anything. + * Will always allocate memory for twice the amount of max elements + * so larger structs should be stored as pointers or indices to an array. + * Can be used in C++ with POD types (without any constructor/destructor). + * + * Be careful not to supply modifying statements to the macro arguments. + * Something like RHMAP_FIT(map, i++); would have unintended results. + * + * Sample usage: + * + * -- Set 2 elements with string keys and mytype_t values: + * mytype_t* map = NULL; + * RHMAP_SET_STR(map, "foo", foo_element); + * RHMAP_SET_STR(map, "bar", bar_element); + * -- now RHMAP_LEN(map) == 2, RHMAP_GET_STR(map, "foo") == foo_element + * + * -- Check if keys exist: + * bool has_foo = RHMAP_HAS_STR(map, "foo"); + * bool has_baz = RHMAP_HAS_STR(map, "baz"); + * -- now has_foo == true, has_baz == false + * + * -- Removing a key: + * bool removed = RHMAP_DEL_STR(map, "bar"); + * bool removed_again = RHMAP_DEL_STR(map, "bar"); + * -- now RHMAP_LEN(map) == 1, removed == true, removed_again == false + * + * -- Add/modify via pointer: + * mytype_t* p_elem = RHMAP_PTR_STR(map, "qux"); + * p_elem->a = 123; + * -- New keys initially have memory uninitialized + * -- Pointers can get invalidated when a key is added/removed + * + * -- Looking up the index for a given key: + * ptrdiff_t idx_foo = RHMAP_IDX_STR(map, "foo"); + * ptrdiff_t idx_invalid = RHMAP_IDX_STR(map, "invalid"); + * -- now idx_foo >= 0, idx_invalid == -1, map[idx_foo] == foo_element + * -- Indices can change when a key is added/removed + * + * -- Clear all elements (keep memory allocated): + * RHMAP_CLEAR(map); + * -- now RHMAP_LEN(map) == 0, RHMAP_CAP(map) == 16 + * + * -- Reserve memory for at least N elements: + * RHMAP_FIT(map, 30); + * -- now RHMAP_LEN(map) == 0, RHMAP_CAP(map) == 64 + * + * -- Add elements with custom hash keys: + * RHMAP_SET(map, my_uint32_hash(key1), some_element); + * RHMAP_SET(map, my_uint32_hash(key2), other_element); + * -- now RHMAP_LEN(map) == 2, _GET/_HAS/_DEL/_PTR/_IDX also exist + * + * -- Iterate elements (random order, order can change on insert): + * for (size_t i = 0, cap = RHMAP_CAP(map); i != cap, i++) + * if (RHMAP_KEY(map, i)) + * ------ here map[i] is the value of key RHMAP_KEY(map, i) + * + * -- Set a custom null value (is zeroed by default): + * RHMAP_SETNULLVAL(map, map_null); + * -- now RHMAP_GET_STR(map, "invalid") == map_null + * + * -- Free allocated memory: + * RHMAP_FREE(map); + * -- now map == NULL, RHMAP_LEN(map) == 0, RHMAP_CAP(map) == 0 + * + * -- To handle running out of memory: + * bool ran_out_of_memory = !RHMAP_TRYFIT(map, 1000); + * -- before setting an element (with SET, PTR or NULLVAL). + * -- When out of memory, map will stay unmodified. + * + */ + +#include /* for malloc, realloc */ +#include /* for memcpy, memset */ +#include /* for ptrdiff_t, size_t */ +#include /* for uint32_t */ + +#define RHMAP_LEN(b) ((b) ? RHMAP__HDR(b)->len : 0) +#define RHMAP_MAX(b) ((b) ? RHMAP__HDR(b)->maxlen : 0) +#define RHMAP_CAP(b) ((b) ? RHMAP__HDR(b)->maxlen + 1 : 0) +#define RHMAP_KEY(b, idx) (RHMAP__HDR(b)->keys[idx]) +#define RHMAP_KEY_STR(b, idx) (RHMAP__HDR(b)->key_strs[idx]) +#define RHMAP_SETNULLVAL(b, val) (RHMAP__FIT1(b), b[-1] = (val)) +#define RHMAP_CLEAR(b) ((b) ? (memset(RHMAP__HDR(b)->keys, 0, RHMAP_CAP(b) * sizeof(uint32_t)), RHMAP__HDR(b)->len = 0) : 0) +#define RHMAP_FREE(b) ((b) ? (rhmap__free(RHMAP__HDR(b)), (b) = NULL) : 0) +#define RHMAP_FIT(b, n) ((!(n) || ((b) && (size_t)(n) * 2 <= RHMAP_MAX(b))) ? 0 : RHMAP__GROW(b, n)) +#define RHMAP_TRYFIT(b, n) (RHMAP_FIT((b), (n)), (!(n) || ((b) && (size_t)(n) * 2 <= RHMAP_MAX(b)))) + +#define RHMAP_SET(b, key, val) RHMAP_SET_FULL(b, key, NULL, val) +#define RHMAP_GET(b, key) RHMAP_GET_FULL(b, key, NULL) +#define RHMAP_HAS(b, key) RHMAP_HAS_FULL(b, key, NULL) +#define RHMAP_DEL(b, key) RHMAP_DEL_FULL(b, key, NULL) +#define RHMAP_PTR(b, key) RHMAP_PTR_FULL(b, key, NULL) +#define RHMAP_IDX(b, key) RHMAP_IDX_FULL(b, key, NULL) + +#ifdef __GNUC__ +#define RHMAP__UNUSED __attribute__((__unused__)) +#else +#define RHMAP__UNUSED +#endif + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4505) //unreferenced local function has been removed +#endif + +#define RHMAP_SET_FULL(b, key, str, val) (RHMAP__FIT1(b), b[rhmap__idx(RHMAP__HDR(b), (key), (str), 1, 0)] = (val)) +#define RHMAP_GET_FULL(b, key, str) (RHMAP__FIT1(b), b[rhmap__idx(RHMAP__HDR(b), (key), (str), 0, 0)]) +#define RHMAP_HAS_FULL(b, key, str) ((b) ? rhmap__idx(RHMAP__HDR(b), (key), (str), 0, 0) != -1 : 0) +#define RHMAP_DEL_FULL(b, key, str) ((b) ? rhmap__idx(RHMAP__HDR(b), (key), (str), 0, sizeof(*(b))) != -1 : 0) +#define RHMAP_PTR_FULL(b, key, str) (RHMAP__FIT1(b), &b[rhmap__idx(RHMAP__HDR(b), (key), (str), 1, 0)]) +#define RHMAP_IDX_FULL(b, key, str) ((b) ? rhmap__idx(RHMAP__HDR(b), (key), (str), 0, 0) : -1) + +#define RHMAP_SET_STR(b, string_key, val) RHMAP_SET_FULL(b, rhmap_hash_string(string_key), string_key, val) +#define RHMAP_GET_STR(b, string_key) RHMAP_GET_FULL(b, rhmap_hash_string(string_key), string_key) +#define RHMAP_HAS_STR(b, string_key) RHMAP_HAS_FULL(b, rhmap_hash_string(string_key), string_key) +#define RHMAP_DEL_STR(b, string_key) RHMAP_DEL_FULL(b, rhmap_hash_string(string_key), string_key) +#define RHMAP_PTR_STR(b, string_key) RHMAP_PTR_FULL(b, rhmap_hash_string(string_key), string_key) +#define RHMAP_IDX_STR(b, string_key) RHMAP_IDX_FULL(b, rhmap_hash_string(string_key), string_key) + +RHMAP__UNUSED static uint32_t rhmap_hash_string(const char* str) +{ + unsigned char c; + uint32_t hash = (uint32_t)0x811c9dc5; + while ((c = (unsigned char)*(str++)) != '\0') + hash = ((hash * (uint32_t)0x01000193) ^ (uint32_t)c); + return (hash ? hash : 1); +} + +struct rhmap__hdr { size_t len, maxlen; uint32_t *keys; char** key_strs; }; +#define RHMAP__HDR(b) (((struct rhmap__hdr *)&(b)[-1])-1) +#define RHMAP__GROW(b, n) (*(void**)(&(b)) = rhmap__grow(RHMAP__HDR(b), (void*)(b), sizeof(*(b)), (size_t)(n))) +#define RHMAP__FIT1(b) ((b) && RHMAP_LEN(b) * 2 <= RHMAP_MAX(b) ? 0 : RHMAP__GROW(b, 0)) + +RHMAP__UNUSED static void* rhmap__grow(struct rhmap__hdr *old_hdr, void* old_ptr, size_t elem_size, size_t reserve) +{ + struct rhmap__hdr *new_hdr; + char *new_vals; + size_t new_max = (old_ptr ? old_hdr->maxlen * 2 + 1 : 15); + while (new_max && new_max / 2 <= reserve) + if (!(new_max = new_max * 2 + 1)) + return old_ptr; /* overflow */ + + new_hdr = (struct rhmap__hdr *)malloc(sizeof(struct rhmap__hdr) + (new_max + 2) * elem_size); + if (!new_hdr) + return old_ptr; /* out of memory */ + + new_hdr->maxlen = new_max; + new_hdr->keys = (uint32_t *)calloc(new_max + 1, sizeof(uint32_t)); + if (!new_hdr->keys) + { + /* out of memory */ + free(new_hdr); + return old_ptr; + } + new_hdr->key_strs = (char**)calloc(new_max + 1, sizeof(char*)); + if (!new_hdr->key_strs) + { + /* out of memory */ + free(new_hdr->keys); + free(new_hdr); + return old_ptr; + } + + new_vals = ((char*)(new_hdr + 1)) + elem_size; + if (old_ptr) + { + size_t i; + char* old_vals = ((char*)(old_hdr + 1)) + elem_size; + for (i = 0; i <= old_hdr->maxlen; i++) + { + uint32_t key, j; + if (!old_hdr->keys[i]) + continue; + for (key = old_hdr->keys[i], j = key;; j++) + { + if (!new_hdr->keys[j &= new_hdr->maxlen]) + { + new_hdr->keys[j] = key; + new_hdr->key_strs[j] = old_hdr->key_strs[i]; + memcpy(new_vals + j * elem_size, old_vals + i * elem_size, elem_size); + break; + } + } + } + memcpy(new_vals - elem_size, old_vals - elem_size, elem_size); + new_hdr->len = old_hdr->len; + free(old_hdr->keys); + free(old_hdr->key_strs); + free(old_hdr); + } + else + { + memset(new_vals - elem_size, 0, elem_size); + new_hdr->len = 0; + } + return new_vals; +} + +RHMAP__UNUSED static ptrdiff_t rhmap__idx(struct rhmap__hdr* hdr, uint32_t key, const char * str, int add, size_t del) +{ + uint32_t i; + + if (!key) + return (ptrdiff_t)-1; + + for (i = key;; i++) + { + if (hdr->keys[i &= hdr->maxlen] == key && (!hdr->key_strs[i] || !str || !strcmp(hdr->key_strs[i], str))) + { + if (del) + { + hdr->len--; + hdr->keys[i] = 0; + free(hdr->key_strs[i]); + hdr->key_strs[i] = NULL; + while ((key = hdr->keys[i = (i + 1) & hdr->maxlen]) != 0) + { + if ((key = (uint32_t)rhmap__idx(hdr, key, str, 1, 0)) == i) continue; + hdr->len--; + hdr->keys[i] = 0; + free(hdr->key_strs[i]); + hdr->key_strs[i] = NULL; + memcpy(((char*)(hdr + 1)) + (key + 1) * del, + ((char*)(hdr + 1)) + (i + 1) * del, del); + } + } + return (ptrdiff_t)i; + } + if (!hdr->keys[i]) + { + if (add) { hdr->len++; hdr->keys[i] = key; if (str) hdr->key_strs[i] = strdup(str); return (ptrdiff_t)i; } + return (ptrdiff_t)-1; + } + } +} + +RHMAP__UNUSED static void rhmap__free(struct rhmap__hdr* hdr) +{ + size_t i; + for (i=0;imaxlen+1;i++) + { + free(hdr->key_strs[i]); + } + free(hdr->key_strs); + free(hdr->keys); + free(hdr); +} + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + +#endif diff --git a/include/defines/cocoa_defines.h b/include/defines/cocoa_defines.h new file mode 100644 index 0000000..51f7179 --- /dev/null +++ b/include/defines/cocoa_defines.h @@ -0,0 +1,73 @@ +/* Copyright (C) 2010-2021 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (cocoa_defines.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 __COCOA_COMMON_DEFINES_H +#define __COCOA_COMMON_DEFINES_H + +#include + +#ifndef MAC_OS_X_VERSION_10_12 +#define MAC_OS_X_VERSION_10_12 101200 +#endif + +#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 +#define NSEventModifierFlagCommand NSCommandKeyMask +#define NSEventModifierFlagControl NSControlKeyMask +#define NSEventModifierFlagHelp NSHelpKeyMask +#define NSEventModifierFlagNumericPad NSNumericPadKeyMask +#define NSEventModifierFlagOption NSAlternateKeyMask +#define NSEventModifierFlagShift NSShiftKeyMask +#define NSCompositingOperationSourceOver NSCompositeSourceOver +#define NSEventMaskApplicationDefined NSApplicationDefinedMask +#define NSEventTypeApplicationDefined NSApplicationDefined +#define NSEventTypeCursorUpdate NSCursorUpdate +#define NSEventTypeMouseMoved NSMouseMoved +#define NSEventTypeMouseEntered NSMouseEntered +#define NSEventTypeMouseExited NSMouseExited +#define NSEventTypeLeftMouseDown NSLeftMouseDown +#define NSEventTypeRightMouseDown NSRightMouseDown +#define NSEventTypeOtherMouseDown NSOtherMouseDown +#define NSEventTypeLeftMouseUp NSLeftMouseUp +#define NSEventTypeRightMouseUp NSRightMouseUp +#define NSEventTypeOtherMouseUp NSOtherMouseUp +#define NSEventTypeLeftMouseDragged NSLeftMouseDragged +#define NSEventTypeRightMouseDragged NSRightMouseDragged +#define NSEventTypeOtherMouseDragged NSOtherMouseDragged +#define NSEventTypeScrollWheel NSScrollWheel +#define NSEventTypeKeyDown NSKeyDown +#define NSEventTypeKeyUp NSKeyUp +#define NSEventTypeFlagsChanged NSFlagsChanged +#define NSEventMaskAny NSAnyEventMask +#define NSWindowStyleMaskBorderless NSBorderlessWindowMask +#define NSWindowStyleMaskClosable NSClosableWindowMask +#define NSWindowStyleMaskFullScreen NSFullScreenWindowMask +#define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask +#define NSWindowStyleMaskResizable NSResizableWindowMask +#define NSWindowStyleMaskTitled NSTitledWindowMask +#define NSAlertStyleCritical NSCriticalAlertStyle +#define NSAlertStyleInformational NSInformationalAlertStyle +#define NSAlertStyleWarning NSWarningAlertStyle +#define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask +#define NSControlSizeRegular NSRegularControlSize +#endif + +#endif diff --git a/include/defines/d3d_defines.h b/include/defines/d3d_defines.h new file mode 100644 index 0000000..a090f4c --- /dev/null +++ b/include/defines/d3d_defines.h @@ -0,0 +1,92 @@ +/* Copyright (C) 2010-2021 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (d3d_defines.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 D3DVIDEO_DEFINES_H +#define D3DVIDEO_DEFINES_H + +#if defined(DEBUG) || defined(_DEBUG) +#define D3D_DEBUG_INFO +#endif + +#if defined(HAVE_D3D9) +/* Direct3D 9 */ +#if 0 +#include +#endif + +#if 0 +#define LPDIRECT3D LPDIRECT3D9 +#define LPDIRECT3DDEVICE LPDIRECT3DDEVICE9 +#define LPDIRECT3DTEXTURE LPDIRECT3DTEXTURE9 +#define LPDIRECT3DCUBETEXTURE LPDIRECT3DCUBETEXTURE9 +#define LPDIRECT3DVERTEXBUFFER LPDIRECT3DVERTEXBUFFER9 +#define LPDIRECT3DVERTEXSHADER LPDIRECT3DVERTEXSHADER9 +#define LPDIRECT3DPIXELSHADER LPDIRECT3DPIXELSHADER9 +#define LPDIRECT3DSURFACE LPDIRECT3DSURFACE9 +#define LPDIRECT3DVERTEXDECLARATION LPDIRECT3DVERTEXDECLARATION9 +#define LPDIRECT3DVOLUMETEXTURE LPDIRECT3DVOLUMETEXTURE9 +#define LPDIRECT3DRESOURCE LPDIRECT3DRESOURCE9 +#define D3DVERTEXELEMENT D3DVERTEXELEMENT9 +#define D3DVIEWPORT D3DVIEWPORT9 +#endif + +#ifndef D3DCREATE_SOFTWARE_VERTEXPROCESSING +#define D3DCREATE_SOFTWARE_VERTEXPROCESSING 0 +#endif + +#elif defined(HAVE_D3D8) +#if 0 +#ifdef _XBOX +#include +#else +#include "../gfx/include/d3d8/d3d8.h" +#endif +#endif + +/* Direct3D 8 */ +#if 0 +#define LPDIRECT3D LPDIRECT3D8 +#define LPDIRECT3DDEVICE LPDIRECT3DDEVICE8 +#define LPDIRECT3DTEXTURE LPDIRECT3DTEXTURE8 +#define LPDIRECT3DCUBETEXTURE LPDIRECT3DCUBETEXTURE8 +#define LPDIRECT3DVOLUMETEXTURE LPDIRECT3DVOLUMETEXTURE8 +#define LPDIRECT3DVERTEXBUFFER LPDIRECT3DVERTEXBUFFER8 +#define LPDIRECT3DVERTEXDECLARATION (void*) +#define LPDIRECT3DSURFACE LPDIRECT3DSURFACE8 +#define LPDIRECT3DRESOURCE LPDIRECT3DRESOURCE8 +#define D3DVERTEXELEMENT D3DVERTEXELEMENT8 +#define D3DVIEWPORT D3DVIEWPORT8 +#endif + +#if !defined(D3DLOCK_NOSYSLOCK) && defined(_XBOX) +#define D3DLOCK_NOSYSLOCK (0) +#endif + +#if 0 +#define D3DSAMP_ADDRESSU D3DTSS_ADDRESSU +#define D3DSAMP_ADDRESSV D3DTSS_ADDRESSV +#define D3DSAMP_MAGFILTER D3DTSS_MAGFILTER +#define D3DSAMP_MINFILTER D3DTSS_MINFILTER +#endif +#endif + +#endif diff --git a/include/defines/gx_defines.h b/include/defines/gx_defines.h new file mode 100644 index 0000000..2b6b904 --- /dev/null +++ b/include/defines/gx_defines.h @@ -0,0 +1,96 @@ +/* Copyright (C) 2010-2021 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (gx_defines.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 _GX_DEFINES_H +#define _GX_DEFINES_H + +#ifdef GEKKO + +#define SYSMEM1_SIZE 0x01800000 + +#define _SHIFTL(v, s, w) ((uint32_t) (((uint32_t)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) ((uint32_t)(((uint32_t)(v) >> (s)) & ((0x01 << (w)) - 1))) + +#define OSThread lwp_t +#define OSCond lwpq_t +#define OSThreadQueue lwpq_t + +#define OSInitMutex(mutex) LWP_MutexInit(mutex, 0) +#define OSLockMutex(mutex) LWP_MutexLock(mutex) +#define OSUnlockMutex(mutex) LWP_MutexUnlock(mutex) +#define OSTryLockMutex(mutex) LWP_MutexTryLock(mutex) + +#define OSInitCond(cond) LWP_CondInit(cond) +#define OSSignalCond(cond) LWP_ThreadSignal(cond) +#define OSWaitCond(cond, mutex) LWP_CondWait(cond, mutex) + +#define OSInitThreadQueue(queue) LWP_InitQueue(queue) +#define OSCloseThreadQueue(queue) LWP_CloseQueue(queue) +#define OSSleepThread(queue) LWP_ThreadSleep(queue) +#define OSJoinThread(thread, val) LWP_JoinThread(thread, val) + +#define OSCreateThread(thread, func, intarg, ptrarg, stackbase, stacksize, priority, attrs) LWP_CreateThread(thread, func, ptrarg, stackbase, stacksize, priority) + +#define BLIT_LINE_16(off) \ +{ \ + const uint32_t *tmp_src = src; \ + uint32_t *tmp_dst = dst; \ + for (unsigned x = 0; x < width2 >> 1; x++, tmp_src += 2, tmp_dst += 8) \ + { \ + tmp_dst[ 0 + off] = BLIT_LINE_16_CONV(tmp_src[0]); \ + tmp_dst[ 1 + off] = BLIT_LINE_16_CONV(tmp_src[1]); \ + } \ + src += tmp_pitch; \ +} + +#define BLIT_LINE_32(off) \ +{ \ + const uint16_t *tmp_src = src; \ + uint16_t *tmp_dst = dst; \ + for (unsigned x = 0; x < width2 >> 3; x++, tmp_src += 8, tmp_dst += 32) \ + { \ + tmp_dst[ 0 + off] = tmp_src[0] | 0xFF00; \ + tmp_dst[ 16 + off] = tmp_src[1]; \ + tmp_dst[ 1 + off] = tmp_src[2] | 0xFF00; \ + tmp_dst[ 17 + off] = tmp_src[3]; \ + tmp_dst[ 2 + off] = tmp_src[4] | 0xFF00; \ + tmp_dst[ 18 + off] = tmp_src[5]; \ + tmp_dst[ 3 + off] = tmp_src[6] | 0xFF00; \ + tmp_dst[ 19 + off] = tmp_src[7]; \ + } \ + src += tmp_pitch; \ +} + +#define CHUNK_FRAMES 64 +#define CHUNK_SIZE (CHUNK_FRAMES * sizeof(uint32_t)) +#define BLOCKS 16 + +#define AIInit AUDIO_Init +#define AIInitDMA AUDIO_InitDMA +#define AIStartDMA AUDIO_StartDMA +#define AIStopDMA AUDIO_StopDMA +#define AIRegisterDMACallback AUDIO_RegisterDMACallback +#define AISetDSPSampleRate AUDIO_SetDSPSampleRate + +#endif + +#endif diff --git a/include/defines/ps3_defines.h b/include/defines/ps3_defines.h new file mode 100644 index 0000000..8114628 --- /dev/null +++ b/include/defines/ps3_defines.h @@ -0,0 +1,704 @@ +/* Copyright (C) 2010-2021 The RetroArch team + * + * --------------------------------------------------------------------------------------- + * The following license statement only applies to this file (ps3_defines.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 _PS3_DEFINES_H +#define _PS3_DEFINES_H + +/*============================================================ + AUDIO PROTOTYPES +============================================================ */ + +#ifdef __PSL1GHT__ +#include