mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-17 04:41:16 +00:00
clang-format
This commit is contained in:
parent
78893bbeac
commit
3958762721
@ -1,135 +1,133 @@
|
|||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#include <psp2/kernel/threadmgr.h>
|
#include <psp2/kernel/threadmgr.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct SceFiosBuffer {
|
||||||
typedef struct SceFiosBuffer {
|
void* pPtr;
|
||||||
void *pPtr;
|
size_t length;
|
||||||
size_t length;
|
} SceFiosBuffer;
|
||||||
} SceFiosBuffer;
|
|
||||||
|
|
||||||
#define SCE_FIOS_THREAD_TYPES 3
|
#define SCE_FIOS_THREAD_TYPES 3
|
||||||
|
|
||||||
typedef struct SceFiosParams
|
typedef struct SceFiosParams {
|
||||||
{
|
uint32_t initialized : 1;
|
||||||
uint32_t initialized : 1;
|
uint32_t paramsSize : 15;
|
||||||
uint32_t paramsSize : 15;
|
uint32_t pathMax : 16;
|
||||||
uint32_t pathMax : 16;
|
uint32_t profiling;
|
||||||
uint32_t profiling;
|
uint32_t ioThreadCount;
|
||||||
uint32_t ioThreadCount;
|
uint32_t threadsPerScheduler;
|
||||||
uint32_t threadsPerScheduler;
|
uint32_t extraFlag1 : 1;
|
||||||
uint32_t extraFlag1 : 1;
|
uint32_t extraFlags : 31;
|
||||||
uint32_t extraFlags : 31;
|
uint32_t maxChunk;
|
||||||
uint32_t maxChunk;
|
uint8_t maxDecompressorThreadCount;
|
||||||
uint8_t maxDecompressorThreadCount;
|
uint8_t reserved1;
|
||||||
uint8_t reserved1;
|
uint8_t reserved2;
|
||||||
uint8_t reserved2;
|
uint8_t reserved3;
|
||||||
uint8_t reserved3;
|
intptr_t reserved4;
|
||||||
intptr_t reserved4;
|
intptr_t reserved5;
|
||||||
intptr_t reserved5;
|
SceFiosBuffer opStorage;
|
||||||
SceFiosBuffer opStorage;
|
SceFiosBuffer fhStorage;
|
||||||
SceFiosBuffer fhStorage;
|
SceFiosBuffer dhStorage;
|
||||||
SceFiosBuffer dhStorage;
|
SceFiosBuffer chunkStorage;
|
||||||
SceFiosBuffer chunkStorage;
|
void* pVprintf;
|
||||||
void* pVprintf;
|
void* pMemcpy;
|
||||||
void* pMemcpy;
|
void* pProfileCallback;
|
||||||
void* pProfileCallback;
|
int threadPriority[SCE_FIOS_THREAD_TYPES];
|
||||||
int threadPriority[SCE_FIOS_THREAD_TYPES];
|
int threadAffinity[SCE_FIOS_THREAD_TYPES];
|
||||||
int threadAffinity[SCE_FIOS_THREAD_TYPES];
|
int threadStackSize[SCE_FIOS_THREAD_TYPES];
|
||||||
int threadStackSize[SCE_FIOS_THREAD_TYPES];
|
} SceFiosParams;
|
||||||
} SceFiosParams;
|
|
||||||
|
|
||||||
#define SCE_KERNEL_HIGHEST_PRIORITY_USER (64)
|
#define SCE_KERNEL_HIGHEST_PRIORITY_USER (64)
|
||||||
#define SCE_KERNEL_LOWEST_PRIORITY_USER (191)
|
#define SCE_KERNEL_LOWEST_PRIORITY_USER (191)
|
||||||
|
|
||||||
#define SCE_FIOS_IO_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_HIGHEST_PRIORITY_USER+2)
|
#define SCE_FIOS_IO_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_HIGHEST_PRIORITY_USER + 2)
|
||||||
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_LOWEST_PRIORITY_USER-2)
|
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_LOWEST_PRIORITY_USER - 2)
|
||||||
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_HIGHEST_PRIORITY_USER+2)
|
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_PRIORITY (SCE_KERNEL_HIGHEST_PRIORITY_USER + 2)
|
||||||
|
|
||||||
#define SCE_FIOS_THREAD_DEFAULT_AFFINITY SCE_KERNEL_CPU_MASK_USER_2
|
#define SCE_FIOS_THREAD_DEFAULT_AFFINITY SCE_KERNEL_CPU_MASK_USER_2
|
||||||
#define SCE_FIOS_IO_THREAD_DEFAULT_AFFINITY SCE_FIOS_THREAD_DEFAULT_AFFINITY
|
#define SCE_FIOS_IO_THREAD_DEFAULT_AFFINITY SCE_FIOS_THREAD_DEFAULT_AFFINITY
|
||||||
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_AFFINITY SCE_KERNEL_THREAD_CPU_AFFINITY_MASK_DEFAULT
|
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_AFFINITY SCE_KERNEL_THREAD_CPU_AFFINITY_MASK_DEFAULT
|
||||||
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_AFFINITY SCE_FIOS_THREAD_DEFAULT_AFFINITY
|
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_AFFINITY SCE_FIOS_THREAD_DEFAULT_AFFINITY
|
||||||
|
|
||||||
#define SCE_FIOS_IO_THREAD_DEFAULT_STACKSIZE (8*1024)
|
#define SCE_FIOS_IO_THREAD_DEFAULT_STACKSIZE (8 * 1024)
|
||||||
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_STACKSIZE (16*1024)
|
#define SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_STACKSIZE (16 * 1024)
|
||||||
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_STACKSIZE (8*1024)
|
#define SCE_FIOS_CALLBACK_THREAD_DEFAULT_STACKSIZE (8 * 1024)
|
||||||
|
|
||||||
#define SCE_FIOS_PARAMS_INITIALIZER { 0, sizeof(SceFiosParams), 0, 0, \
|
#define SCE_FIOS_PARAMS_INITIALIZER \
|
||||||
2, 2, \
|
{ \
|
||||||
0, 0, \
|
0, sizeof(SceFiosParams), 0, 0, 2, 2, 0, 0, (256 * 1024), 2, 0, 0, 0, 0, 0, {0, 0}, {0, 0}, {0, 0}, {0, 0}, \
|
||||||
(256*1024), \
|
NULL, NULL, NULL, \
|
||||||
2, 0, 0, 0, 0, 0, \
|
{SCE_FIOS_IO_THREAD_DEFAULT_PRIORITY, \
|
||||||
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_PRIORITY, \
|
||||||
NULL, NULL, NULL, \
|
SCE_FIOS_CALLBACK_THREAD_DEFAULT_PRIORITY}, \
|
||||||
{ SCE_FIOS_IO_THREAD_DEFAULT_PRIORITY, SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_PRIORITY, SCE_FIOS_CALLBACK_THREAD_DEFAULT_PRIORITY }, \
|
{SCE_FIOS_IO_THREAD_DEFAULT_AFFINITY, \
|
||||||
{ SCE_FIOS_IO_THREAD_DEFAULT_AFFINITY, SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_AFFINITY, SCE_FIOS_CALLBACK_THREAD_DEFAULT_AFFINITY}, \
|
SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_AFFINITY, \
|
||||||
{ SCE_FIOS_IO_THREAD_DEFAULT_STACKSIZE, SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_STACKSIZE, SCE_FIOS_CALLBACK_THREAD_DEFAULT_STACKSIZE}}
|
SCE_FIOS_CALLBACK_THREAD_DEFAULT_AFFINITY}, \
|
||||||
|
{ \
|
||||||
|
SCE_FIOS_IO_THREAD_DEFAULT_STACKSIZE, SCE_FIOS_DECOMPRESSOR_THREAD_DEFAULT_STACKSIZE, \
|
||||||
|
SCE_FIOS_CALLBACK_THREAD_DEFAULT_STACKSIZE \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define SCE_FIOS_IO_THREAD 0
|
#define SCE_FIOS_IO_THREAD 0
|
||||||
#define SCE_FIOS_DECOMPRESSOR_THREAD 1
|
#define SCE_FIOS_DECOMPRESSOR_THREAD 1
|
||||||
#define SCE_FIOS_CALLBACK_THREAD 2
|
#define SCE_FIOS_CALLBACK_THREAD 2
|
||||||
|
|
||||||
#define SCE_FIOS_FH_SIZE 80
|
#define SCE_FIOS_FH_SIZE 80
|
||||||
#define SCE_FIOS_DH_SIZE 80
|
#define SCE_FIOS_DH_SIZE 80
|
||||||
#define SCE_FIOS_OP_SIZE 168
|
#define SCE_FIOS_OP_SIZE 168
|
||||||
#define SCE_FIOS_CHUNK_SIZE 64
|
#define SCE_FIOS_CHUNK_SIZE 64
|
||||||
|
|
||||||
#define SCE_FIOS_ALIGN_UP(val,align) (((val) + ((align)-1)) & ~((align)-1))
|
#define SCE_FIOS_ALIGN_UP(val, align) (((val) + ((align) -1)) & ~((align) -1))
|
||||||
|
|
||||||
#define SCE_FIOS_STORAGE_SIZE(num, size) \
|
#define SCE_FIOS_STORAGE_SIZE(num, size) (((num) * (size)) + SCE_FIOS_ALIGN_UP(SCE_FIOS_ALIGN_UP((num), 8) / 8, 8))
|
||||||
(((num) * (size)) + SCE_FIOS_ALIGN_UP(SCE_FIOS_ALIGN_UP((num), 8) / 8, 8))
|
|
||||||
|
|
||||||
#define SCE_FIOS_DH_STORAGE_SIZE(numDHs, pathMax) \
|
#define SCE_FIOS_DH_STORAGE_SIZE(numDHs, pathMax) SCE_FIOS_STORAGE_SIZE(numDHs, SCE_FIOS_DH_SIZE + pathMax)
|
||||||
SCE_FIOS_STORAGE_SIZE(numDHs, SCE_FIOS_DH_SIZE + pathMax)
|
|
||||||
|
|
||||||
#define SCE_FIOS_FH_STORAGE_SIZE(numFHs,pathMax) \
|
#define SCE_FIOS_FH_STORAGE_SIZE(numFHs, pathMax) SCE_FIOS_STORAGE_SIZE(numFHs, SCE_FIOS_FH_SIZE + pathMax)
|
||||||
SCE_FIOS_STORAGE_SIZE(numFHs, SCE_FIOS_FH_SIZE + pathMax)
|
|
||||||
|
|
||||||
#define SCE_FIOS_OP_STORAGE_SIZE(numOps,pathMax) \
|
#define SCE_FIOS_OP_STORAGE_SIZE(numOps, pathMax) SCE_FIOS_STORAGE_SIZE(numOps, SCE_FIOS_OP_SIZE + pathMax)
|
||||||
SCE_FIOS_STORAGE_SIZE(numOps, SCE_FIOS_OP_SIZE + pathMax)
|
|
||||||
|
|
||||||
#define SCE_FIOS_CHUNK_STORAGE_SIZE(numChunks) \
|
#define SCE_FIOS_CHUNK_STORAGE_SIZE(numChunks) SCE_FIOS_STORAGE_SIZE(numChunks, SCE_FIOS_CHUNK_SIZE)
|
||||||
SCE_FIOS_STORAGE_SIZE(numChunks, SCE_FIOS_CHUNK_SIZE)
|
|
||||||
|
|
||||||
int sceFiosInitialize(SceFiosParams* params);
|
int sceFiosInitialize(SceFiosParams* params);
|
||||||
|
|
||||||
|
typedef int64_t SceFiosTime;
|
||||||
|
|
||||||
typedef int64_t SceFiosTime;
|
typedef int32_t SceFiosHandle;
|
||||||
|
|
||||||
typedef int32_t SceFiosHandle;
|
typedef SceFiosHandle SceFiosFH;
|
||||||
|
|
||||||
typedef SceFiosHandle SceFiosFH;
|
typedef struct SceFiosOpenParams {
|
||||||
|
uint32_t openFlags : 16;
|
||||||
typedef struct SceFiosOpenParams
|
uint32_t opFlags : 16;
|
||||||
{
|
uint32_t reserved;
|
||||||
uint32_t openFlags:16;
|
SceFiosBuffer buffer;
|
||||||
uint32_t opFlags:16;
|
} SceFiosOpenParams;
|
||||||
uint32_t reserved;
|
|
||||||
SceFiosBuffer buffer;
|
|
||||||
} SceFiosOpenParams;
|
|
||||||
|
|
||||||
typedef struct SceFiosOpAttr
|
|
||||||
{
|
|
||||||
SceFiosTime deadline;
|
|
||||||
void* pCallback;
|
|
||||||
void * pCallbackContext;
|
|
||||||
int32_t priority : 8;
|
|
||||||
uint32_t opflags : 24;
|
|
||||||
uint32_t userTag;
|
|
||||||
void * userPtr;
|
|
||||||
void * pReserved;
|
|
||||||
} SceFiosOpAttr;
|
|
||||||
|
|
||||||
|
|
||||||
int sceFiosFHOpenWithModeSync(const SceFiosOpAttr *pAttr, SceFiosFH *pOutFH, const char *pPath, const SceFiosOpenParams *pOpenParams, int32_t nativeMode);
|
|
||||||
|
|
||||||
|
typedef struct SceFiosOpAttr {
|
||||||
|
SceFiosTime deadline;
|
||||||
|
void* pCallback;
|
||||||
|
void* pCallbackContext;
|
||||||
|
int32_t priority : 8;
|
||||||
|
uint32_t opflags : 24;
|
||||||
|
uint32_t userTag;
|
||||||
|
void* userPtr;
|
||||||
|
void* pReserved;
|
||||||
|
} SceFiosOpAttr;
|
||||||
|
|
||||||
|
int sceFiosFHOpenWithModeSync(
|
||||||
|
const SceFiosOpAttr* pAttr,
|
||||||
|
SceFiosFH* pOutFH,
|
||||||
|
const char* pPath,
|
||||||
|
const SceFiosOpenParams* pOpenParams,
|
||||||
|
int32_t nativeMode
|
||||||
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,153 +15,150 @@
|
|||||||
#define _DICTIONARY_H_
|
#define _DICTIONARY_H_
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Includes
|
Includes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "pafstd.h"
|
#include "pafstd.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
New types
|
New types
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
@brief Dictionary object
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
This object contains a list of string/string associations. Each
|
||||||
/**
|
association is identified by a unique string key. Looking up values
|
||||||
@brief Dictionary object
|
in the dictionary is speeded up by the use of a (hopefully collision-free)
|
||||||
|
hash function.
|
||||||
|
*/
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
typedef struct _dictionary_ {
|
||||||
|
unsigned n; /** Number of entries in dictionary */
|
||||||
|
size_t size; /** Storage size */
|
||||||
|
char** val; /** List of string values */
|
||||||
|
char** key; /** List of string keys */
|
||||||
|
unsigned* hash; /** List of hash values for keys */
|
||||||
|
} dictionary;
|
||||||
|
|
||||||
This object contains a list of string/string associations. Each
|
/*---------------------------------------------------------------------------
|
||||||
association is identified by a unique string key. Looking up values
|
Function prototypes
|
||||||
in the dictionary is speeded up by the use of a (hopefully collision-free)
|
---------------------------------------------------------------------------*/
|
||||||
hash function.
|
|
||||||
*/
|
|
||||||
/*-------------------------------------------------------------------------*/
|
|
||||||
typedef struct _dictionary_ {
|
|
||||||
unsigned n ; /** Number of entries in dictionary */
|
|
||||||
size_t size ; /** Storage size */
|
|
||||||
char ** val ; /** List of string values */
|
|
||||||
char ** key ; /** List of string keys */
|
|
||||||
unsigned * hash ; /** List of hash values for keys */
|
|
||||||
} dictionary ;
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
@brief Compute the hash key for a string.
|
||||||
|
@param key Character string to use for key.
|
||||||
|
@return 1 unsigned int on at least 32 bits.
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
This hash function has been taken from an Article in Dr Dobbs Journal.
|
||||||
Function prototypes
|
This is normally a collision-free function, distributing keys evenly.
|
||||||
---------------------------------------------------------------------------*/
|
The key is stored anyway in the struct so that collision can be avoided
|
||||||
|
by comparing the key itself in last resort.
|
||||||
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
unsigned dictionary_hash(const char* key);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Compute the hash key for a string.
|
@brief Create a new dictionary object.
|
||||||
@param key Character string to use for key.
|
@param size Optional initial size of the dictionary.
|
||||||
@return 1 unsigned int on at least 32 bits.
|
@return 1 newly allocated dictionary object.
|
||||||
|
|
||||||
This hash function has been taken from an Article in Dr Dobbs Journal.
|
This function allocates a new dictionary object of given size and returns
|
||||||
This is normally a collision-free function, distributing keys evenly.
|
it. If you do not know in advance (roughly) the number of entries in the
|
||||||
The key is stored anyway in the struct so that collision can be avoided
|
dictionary, give size=0.
|
||||||
by comparing the key itself in last resort.
|
*/
|
||||||
*/
|
/*--------------------------------------------------------------------------*/
|
||||||
/*--------------------------------------------------------------------------*/
|
dictionary* dictionary_new(size_t size);
|
||||||
unsigned dictionary_hash(const char * key);
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Create a new dictionary object.
|
@brief Delete a dictionary object
|
||||||
@param size Optional initial size of the dictionary.
|
@param d dictionary object to deallocate.
|
||||||
@return 1 newly allocated dictionary object.
|
@return void
|
||||||
|
|
||||||
This function allocates a new dictionary object of given size and returns
|
Deallocate a dictionary object and all memory associated to it.
|
||||||
it. If you do not know in advance (roughly) the number of entries in the
|
*/
|
||||||
dictionary, give size=0.
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
void dictionary_del(dictionary* vd);
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
dictionary * dictionary_new(size_t size);
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Delete a dictionary object
|
@brief Get a value from a dictionary.
|
||||||
@param d dictionary object to deallocate.
|
@param d dictionary object to search.
|
||||||
@return void
|
@param key Key to look for in the dictionary.
|
||||||
|
@param def Default value to return if key not found.
|
||||||
|
@return 1 pointer to internally allocated character string.
|
||||||
|
|
||||||
Deallocate a dictionary object and all memory associated to it.
|
This function locates a key in a dictionary and returns a pointer to its
|
||||||
*/
|
value, or the passed 'def' pointer if no such key can be found in
|
||||||
/*--------------------------------------------------------------------------*/
|
dictionary. The returned character pointer points to data internal to the
|
||||||
void dictionary_del(dictionary * vd);
|
dictionary object, you should not try to free it or modify it.
|
||||||
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
const char* dictionary_get(const dictionary* d, const char* key, const char* def);
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Get a value from a dictionary.
|
@brief Set a value in a dictionary.
|
||||||
@param d dictionary object to search.
|
@param d dictionary object to modify.
|
||||||
@param key Key to look for in the dictionary.
|
@param key Key to modify or add.
|
||||||
@param def Default value to return if key not found.
|
@param val Value to add.
|
||||||
@return 1 pointer to internally allocated character string.
|
@return int 0 if Ok, anything else otherwise
|
||||||
|
|
||||||
This function locates a key in a dictionary and returns a pointer to its
|
If the given key is found in the dictionary, the associated value is
|
||||||
value, or the passed 'def' pointer if no such key can be found in
|
replaced by the provided one. If the key cannot be found in the
|
||||||
dictionary. The returned character pointer points to data internal to the
|
dictionary, it is added to it.
|
||||||
dictionary object, you should not try to free it or modify it.
|
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
const char * dictionary_get(const dictionary * d, const char * key, const char * def);
|
|
||||||
|
|
||||||
|
It is Ok to provide a NULL value for val, but NULL values for the dictionary
|
||||||
|
or the key are considered as errors: the function will return immediately
|
||||||
|
in such a case.
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
Notice that if you dictionary_set a variable to NULL, a call to
|
||||||
/**
|
dictionary_get will return a NULL value: the variable will be found, and
|
||||||
@brief Set a value in a dictionary.
|
its value (NULL) is returned. In other words, setting the variable
|
||||||
@param d dictionary object to modify.
|
content to NULL is equivalent to deleting the variable from the
|
||||||
@param key Key to modify or add.
|
dictionary. It is not possible (in this implementation) to have a key in
|
||||||
@param val Value to add.
|
the dictionary without value.
|
||||||
@return int 0 if Ok, anything else otherwise
|
|
||||||
|
|
||||||
If the given key is found in the dictionary, the associated value is
|
This function returns non-zero in case of failure.
|
||||||
replaced by the provided one. If the key cannot be found in the
|
*/
|
||||||
dictionary, it is added to it.
|
/*--------------------------------------------------------------------------*/
|
||||||
|
int dictionary_set(dictionary* vd, const char* key, const char* val);
|
||||||
|
|
||||||
It is Ok to provide a NULL value for val, but NULL values for the dictionary
|
/*-------------------------------------------------------------------------*/
|
||||||
or the key are considered as errors: the function will return immediately
|
/**
|
||||||
in such a case.
|
@brief Delete a key in a dictionary
|
||||||
|
@param d dictionary object to modify.
|
||||||
|
@param key Key to remove.
|
||||||
|
@return void
|
||||||
|
|
||||||
Notice that if you dictionary_set a variable to NULL, a call to
|
This function deletes a key in a dictionary. Nothing is done if the
|
||||||
dictionary_get will return a NULL value: the variable will be found, and
|
key cannot be found.
|
||||||
its value (NULL) is returned. In other words, setting the variable
|
*/
|
||||||
content to NULL is equivalent to deleting the variable from the
|
/*--------------------------------------------------------------------------*/
|
||||||
dictionary. It is not possible (in this implementation) to have a key in
|
void dictionary_unset(dictionary* d, const char* key);
|
||||||
the dictionary without value.
|
|
||||||
|
|
||||||
This function returns non-zero in case of failure.
|
/*-------------------------------------------------------------------------*/
|
||||||
*/
|
/**
|
||||||
/*--------------------------------------------------------------------------*/
|
@brief Dump a dictionary to an opened file pointer.
|
||||||
int dictionary_set(dictionary * vd, const char * key, const char * val);
|
@param d Dictionary to dump
|
||||||
|
@param f Opened file pointer.
|
||||||
|
@return void
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
Dumps a dictionary onto an opened file pointer. Key pairs are printed out
|
||||||
/**
|
as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
|
||||||
@brief Delete a key in a dictionary
|
output file pointers.
|
||||||
@param d dictionary object to modify.
|
*/
|
||||||
@param key Key to remove.
|
/*--------------------------------------------------------------------------*/
|
||||||
@return void
|
void dictionary_dump(const dictionary* d, FILE* out);
|
||||||
|
|
||||||
This function deletes a key in a dictionary. Nothing is done if the
|
|
||||||
key cannot be found.
|
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void dictionary_unset(dictionary * d, const char * key);
|
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
|
||||||
/**
|
|
||||||
@brief Dump a dictionary to an opened file pointer.
|
|
||||||
@param d Dictionary to dump
|
|
||||||
@param f Opened file pointer.
|
|
||||||
@return void
|
|
||||||
|
|
||||||
Dumps a dictionary onto an opened file pointer. Key pairs are printed out
|
|
||||||
as @c [Key]=[Value], one per line. It is Ok to provide stdout or stderr as
|
|
||||||
output file pointers.
|
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void dictionary_dump(const dictionary * d, FILE * out);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,433 +11,430 @@
|
|||||||
#define _INIPARSER_H_
|
#define _INIPARSER_H_
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------
|
/*---------------------------------------------------------------------------
|
||||||
Includes
|
Includes
|
||||||
---------------------------------------------------------------------------*/
|
---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "dictionary.h"
|
#include "dictionary.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Configure a function to receive the error messages.
|
@brief Configure a function to receive the error messages.
|
||||||
@param errback Function to call.
|
@param errback Function to call.
|
||||||
|
|
||||||
By default, the error will be printed on stderr. If a null pointer is passed
|
By default, the error will be printed on stderr. If a null pointer is passed
|
||||||
as errback the error callback will be switched back to default.
|
as errback the error callback will be switched back to default.
|
||||||
*/
|
*/
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
void iniparser_set_error_callback(int (*errback)(const char *, ...));
|
void iniparser_set_error_callback(int (*errback)(const char*, ...));
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
@brief Get number of sections in a dictionary
|
@brief Get number of sections in a dictionary
|
||||||
@param d Dictionary to examine
|
@param d Dictionary to examine
|
||||||
@return int Number of sections found in dictionary
|
@return int Number of sections found in dictionary
|
||||||
|
|
||||||
This function returns the number of sections found in a dictionary.
|
This function returns the number of sections found in a dictionary.
|
||||||
The test to recognize sections is done on the string stored in the
|
The test to recognize sections is done on the string stored in the
|
||||||
dictionary: a section name is given as "section" whereas a key is
|
dictionary: a section name is given as "section" whereas a key is
|
||||||
stored as "section:key", thus the test looks for entries that do not
|
stored as "section:key", thus the test looks for entries that do not
|
||||||
contain a colon.
|
contain a colon.
|
||||||
|
|
||||||
This clearly fails in the case a section name contains a colon, but
|
This clearly fails in the case a section name contains a colon, but
|
||||||
this should simply be avoided.
|
this should simply be avoided.
|
||||||
|
|
||||||
This function returns -1 in case of error.
|
This function returns -1 in case of error.
|
||||||
*/
|
*/
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
int iniparser_getnsec(const dictionary * d);
|
int iniparser_getnsec(const dictionary* d);
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
/*-------------------------------------------------------------------------*/
|
/**
|
||||||
/**
|
@brief Get name for section n in a dictionary.
|
||||||
@brief Get name for section n in a dictionary.
|
@param d Dictionary to examine
|
||||||
@param d Dictionary to examine
|
@param n Section number (from 0 to nsec-1).
|
||||||
@param n Section number (from 0 to nsec-1).
|
@return Pointer to char string
|
||||||
@return Pointer to char string
|
|
||||||
|
This function locates the n-th section in a dictionary and returns
|
||||||
This function locates the n-th section in a dictionary and returns
|
its name as a pointer to a string statically allocated inside the
|
||||||
its name as a pointer to a string statically allocated inside the
|
dictionary. Do not free or modify the returned string!
|
||||||
dictionary. Do not free or modify the returned string!
|
|
||||||
|
This function returns NULL in case of error.
|
||||||
This function returns NULL in case of error.
|
*/
|
||||||
*/
|
/*--------------------------------------------------------------------------*/
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
const char* iniparser_getsecname(const dictionary* d, int n);
|
||||||
const char * iniparser_getsecname(const dictionary * d, int n);
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
/*-------------------------------------------------------------------------*/
|
@brief Save a dictionary to a loadable ini file
|
||||||
/**
|
@param d Dictionary to dump
|
||||||
@brief Save a dictionary to a loadable ini file
|
@param f Opened file pointer to dump to
|
||||||
@param d Dictionary to dump
|
|
||||||
@param f Opened file pointer to dump to
|
This function dumps a given dictionary into a loadable ini file.
|
||||||
|
It is Ok to specify @c stderr or @c stdout as output files.
|
||||||
This function dumps a given dictionary into a loadable ini file.
|
|
||||||
It is Ok to specify @c stderr or @c stdout as output files.
|
All values are quoted, these charecters are escaped:
|
||||||
|
|
||||||
All values are quoted, these charecters are escaped:
|
- ' : the quote character (e.g. "String with \"Quotes\"")
|
||||||
|
- \ : the backslash character (e.g. "C:\\tmp")
|
||||||
- ' : the quote character (e.g. "String with \"Quotes\"")
|
|
||||||
- \ : the backslash character (e.g. "C:\\tmp")
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
void iniparser_dump_ini(const dictionary* d, FILE* f);
|
||||||
|
|
||||||
void iniparser_dump_ini(const dictionary * d, FILE * f);
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
/*-------------------------------------------------------------------------*/
|
@brief Save a dictionary section to a loadable ini file
|
||||||
/**
|
@param d Dictionary to dump
|
||||||
@brief Save a dictionary section to a loadable ini file
|
@param s Section name of dictionary to dump
|
||||||
@param d Dictionary to dump
|
@param f Opened file pointer to dump to
|
||||||
@param s Section name of dictionary to dump
|
|
||||||
@param f Opened file pointer to dump to
|
This function dumps a given section of a given dictionary into a loadable ini
|
||||||
|
file. It is Ok to specify @c stderr or @c stdout as output files.
|
||||||
This function dumps a given section of a given dictionary into a loadable ini
|
*/
|
||||||
file. It is Ok to specify @c stderr or @c stdout as output files.
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
void iniparser_dumpsection_ini(const dictionary* d, const char* s, FILE* f);
|
||||||
|
|
||||||
void iniparser_dumpsection_ini(const dictionary * d, const char * s, FILE * f);
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
/*-------------------------------------------------------------------------*/
|
@brief Dump a dictionary to an opened file pointer.
|
||||||
/**
|
@param d Dictionary to dump.
|
||||||
@brief Dump a dictionary to an opened file pointer.
|
@param f Opened file pointer to dump to.
|
||||||
@param d Dictionary to dump.
|
|
||||||
@param f Opened file pointer to dump to.
|
This function prints out the contents of a dictionary, one element by
|
||||||
|
line, onto the provided file pointer. It is OK to specify @c stderr
|
||||||
This function prints out the contents of a dictionary, one element by
|
or @c stdout as output files. This function is meant for debugging
|
||||||
line, onto the provided file pointer. It is OK to specify @c stderr
|
purposes mostly.
|
||||||
or @c stdout as output files. This function is meant for debugging
|
*/
|
||||||
purposes mostly.
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
void iniparser_dump(const dictionary* d, FILE* f);
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void iniparser_dump(const dictionary * d, FILE * f);
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
/*-------------------------------------------------------------------------*/
|
@brief Get the number of keys in a section of a dictionary.
|
||||||
/**
|
@param d Dictionary to examine
|
||||||
@brief Get the number of keys in a section of a dictionary.
|
@param s Section name of dictionary to examine
|
||||||
@param d Dictionary to examine
|
@return Number of keys in section
|
||||||
@param s Section name of dictionary to examine
|
*/
|
||||||
@return Number of keys in section
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
int iniparser_getsecnkeys(const dictionary* d, const char* s);
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
int iniparser_getsecnkeys(const dictionary * d, const char * s);
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
/*-------------------------------------------------------------------------*/
|
@brief Get the number of keys in a section of a dictionary.
|
||||||
/**
|
@param d Dictionary to examine
|
||||||
@brief Get the number of keys in a section of a dictionary.
|
@param s Section name of dictionary to examine
|
||||||
@param d Dictionary to examine
|
@param keys Already allocated array to store the keys in
|
||||||
@param s Section name of dictionary to examine
|
@return The pointer passed as `keys` argument or NULL in case of error
|
||||||
@param keys Already allocated array to store the keys in
|
|
||||||
@return The pointer passed as `keys` argument or NULL in case of error
|
This function queries a dictionary and finds all keys in a given section.
|
||||||
|
The keys argument should be an array of pointers which size has been
|
||||||
This function queries a dictionary and finds all keys in a given section.
|
determined by calling `iniparser_getsecnkeys` function prior to this one.
|
||||||
The keys argument should be an array of pointers which size has been
|
|
||||||
determined by calling `iniparser_getsecnkeys` function prior to this one.
|
Each pointer in the returned char pointer-to-pointer is pointing to
|
||||||
|
a string allocated in the dictionary; do not free or modify them.
|
||||||
Each pointer in the returned char pointer-to-pointer is pointing to
|
*/
|
||||||
a string allocated in the dictionary; do not free or modify them.
|
/*--------------------------------------------------------------------------*/
|
||||||
*/
|
const char** iniparser_getseckeys(const dictionary* d, const char* s, const char** keys);
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
const char ** iniparser_getseckeys(const dictionary * d, const char * s, const char ** keys);
|
/*-------------------------------------------------------------------------*/
|
||||||
|
/**
|
||||||
|
@brief Get the string associated to a key
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key
|
@param def Default value to return if key not found.
|
||||||
@param d Dictionary to search
|
@return pointer to statically allocated character string
|
||||||
@param key Key string to look for
|
|
||||||
@param def Default value to return if key not found.
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return pointer to statically allocated character string
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the pointer passed as 'def' is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
The returned char pointer is pointing to a string allocated in
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
the dictionary, do not free or modify it.
|
||||||
the pointer passed as 'def' is returned.
|
*/
|
||||||
The returned char pointer is pointing to a string allocated in
|
/*--------------------------------------------------------------------------*/
|
||||||
the dictionary, do not free or modify it.
|
const char* iniparser_getstring(const dictionary* d, const char* key, const char* def);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
const char * iniparser_getstring(const dictionary * d, const char * key, const char * def);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to an int
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to an int
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return integer
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return integer
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
Supported values for integers include the usual C notation
|
||||||
the notfound value is returned.
|
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
||||||
|
are supported. Examples:
|
||||||
Supported values for integers include the usual C notation
|
|
||||||
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
- "42" -> 42
|
||||||
are supported. Examples:
|
- "042" -> 34 (octal -> decimal)
|
||||||
|
- "0x42" -> 66 (hexa -> decimal)
|
||||||
- "42" -> 42
|
|
||||||
- "042" -> 34 (octal -> decimal)
|
Warning: the conversion may overflow in various ways. Conversion is
|
||||||
- "0x42" -> 66 (hexa -> decimal)
|
totally outsourced to strtol(), see the associated man page for overflow
|
||||||
|
handling.
|
||||||
Warning: the conversion may overflow in various ways. Conversion is
|
|
||||||
totally outsourced to strtol(), see the associated man page for overflow
|
Credits: Thanks to A. Becker for suggesting strtol()
|
||||||
handling.
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
Credits: Thanks to A. Becker for suggesting strtol()
|
int iniparser_getint(const dictionary* d, const char* key, int notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
int iniparser_getint(const dictionary * d, const char * key, int notfound);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to an long int
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to an long int
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return integer
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return integer
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
Supported values for integers include the usual C notation
|
||||||
the notfound value is returned.
|
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
||||||
|
are supported. Examples:
|
||||||
Supported values for integers include the usual C notation
|
|
||||||
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
- "42" -> 42
|
||||||
are supported. Examples:
|
- "042" -> 34 (octal -> decimal)
|
||||||
|
- "0x42" -> 66 (hexa -> decimal)
|
||||||
- "42" -> 42
|
|
||||||
- "042" -> 34 (octal -> decimal)
|
Warning: the conversion may overflow in various ways. Conversion is
|
||||||
- "0x42" -> 66 (hexa -> decimal)
|
totally outsourced to strtol(), see the associated man page for overflow
|
||||||
|
handling.
|
||||||
Warning: the conversion may overflow in various ways. Conversion is
|
*/
|
||||||
totally outsourced to strtol(), see the associated man page for overflow
|
/*--------------------------------------------------------------------------*/
|
||||||
handling.
|
long int iniparser_getlongint(const dictionary* d, const char* key, long int notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
long int iniparser_getlongint(const dictionary * d, const char * key, long int notfound);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to an int64_t
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to an int64_t
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return integer
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return integer
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
Supported values for integers include the usual C notation
|
||||||
the notfound value is returned.
|
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
||||||
|
are supported. Examples:
|
||||||
Supported values for integers include the usual C notation
|
|
||||||
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
- "42" -> 42
|
||||||
are supported. Examples:
|
- "042" -> 34 (octal -> decimal)
|
||||||
|
- "0x42" -> 66 (hexa -> decimal)
|
||||||
- "42" -> 42
|
|
||||||
- "042" -> 34 (octal -> decimal)
|
Warning: the conversion may overflow in various ways. Conversion is
|
||||||
- "0x42" -> 66 (hexa -> decimal)
|
totally outsourced to strtoimax(), see the associated man page for overflow
|
||||||
|
handling.
|
||||||
Warning: the conversion may overflow in various ways. Conversion is
|
|
||||||
totally outsourced to strtoimax(), see the associated man page for overflow
|
This function is usefull on 32bit architectures where `long int` is only
|
||||||
handling.
|
32bit.
|
||||||
|
*/
|
||||||
This function is usefull on 32bit architectures where `long int` is only
|
/*--------------------------------------------------------------------------*/
|
||||||
32bit.
|
int64_t iniparser_getint64(const dictionary* d, const char* key, int64_t notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
int64_t iniparser_getint64(const dictionary * d, const char * key, int64_t notfound);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to an uint64_t
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to an uint64_t
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return integer
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return integer
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
Supported values for integers include the usual C notation
|
||||||
the notfound value is returned.
|
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
||||||
|
are supported. Examples:
|
||||||
Supported values for integers include the usual C notation
|
|
||||||
so decimal, octal (starting with 0) and hexadecimal (starting with 0x)
|
- "42" -> 42
|
||||||
are supported. Examples:
|
- "042" -> 34 (octal -> decimal)
|
||||||
|
- "0x42" -> 66 (hexa -> decimal)
|
||||||
- "42" -> 42
|
|
||||||
- "042" -> 34 (octal -> decimal)
|
Warning: the conversion may overflow in various ways. Conversion is
|
||||||
- "0x42" -> 66 (hexa -> decimal)
|
totally outsourced to strtoumax(), see the associated man page for overflow
|
||||||
|
handling.
|
||||||
Warning: the conversion may overflow in various ways. Conversion is
|
|
||||||
totally outsourced to strtoumax(), see the associated man page for overflow
|
This function is usefull on 32bit architectures where `long int` is only
|
||||||
handling.
|
32bit.
|
||||||
|
*/
|
||||||
This function is usefull on 32bit architectures where `long int` is only
|
/*--------------------------------------------------------------------------*/
|
||||||
32bit.
|
uint64_t iniparser_getuint64(const dictionary* d, const char* key, uint64_t notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
uint64_t iniparser_getuint64(const dictionary * d, const char * key, uint64_t notfound);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to a double
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to a double
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return double
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return double
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
*/
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
/*--------------------------------------------------------------------------*/
|
||||||
the notfound value is returned.
|
double iniparser_getdouble(const dictionary* d, const char* key, double notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
double iniparser_getdouble(const dictionary * d, const char * key, double notfound);
|
/**
|
||||||
|
@brief Get the string associated to a key, convert to a boolean
|
||||||
/*-------------------------------------------------------------------------*/
|
@param d Dictionary to search
|
||||||
/**
|
@param key Key string to look for
|
||||||
@brief Get the string associated to a key, convert to a boolean
|
@param notfound Value to return in case of error
|
||||||
@param d Dictionary to search
|
@return integer
|
||||||
@param key Key string to look for
|
|
||||||
@param notfound Value to return in case of error
|
This function queries a dictionary for a key. A key as read from an
|
||||||
@return integer
|
ini file is given as "section:key". If the key cannot be found,
|
||||||
|
the notfound value is returned.
|
||||||
This function queries a dictionary for a key. A key as read from an
|
|
||||||
ini file is given as "section:key". If the key cannot be found,
|
A true boolean is found if one of the following is matched:
|
||||||
the notfound value is returned.
|
|
||||||
|
- A string starting with 'y'
|
||||||
A true boolean is found if one of the following is matched:
|
- A string starting with 'Y'
|
||||||
|
- A string starting with 't'
|
||||||
- A string starting with 'y'
|
- A string starting with 'T'
|
||||||
- A string starting with 'Y'
|
- A string starting with '1'
|
||||||
- A string starting with 't'
|
|
||||||
- A string starting with 'T'
|
A false boolean is found if one of the following is matched:
|
||||||
- A string starting with '1'
|
|
||||||
|
- A string starting with 'n'
|
||||||
A false boolean is found if one of the following is matched:
|
- A string starting with 'N'
|
||||||
|
- A string starting with 'f'
|
||||||
- A string starting with 'n'
|
- A string starting with 'F'
|
||||||
- A string starting with 'N'
|
- A string starting with '0'
|
||||||
- A string starting with 'f'
|
|
||||||
- A string starting with 'F'
|
The notfound value returned if no boolean is identified, does not
|
||||||
- A string starting with '0'
|
necessarily have to be 0 or 1.
|
||||||
|
*/
|
||||||
The notfound value returned if no boolean is identified, does not
|
/*--------------------------------------------------------------------------*/
|
||||||
necessarily have to be 0 or 1.
|
int iniparser_getboolean(const dictionary* d, const char* key, int notfound);
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
int iniparser_getboolean(const dictionary * d, const char * key, int notfound);
|
/**
|
||||||
|
@brief Set an entry in a dictionary.
|
||||||
|
@param ini Dictionary to modify.
|
||||||
/*-------------------------------------------------------------------------*/
|
@param entry Entry to modify (entry name)
|
||||||
/**
|
@param val New value to associate to the entry.
|
||||||
@brief Set an entry in a dictionary.
|
@return int 0 if Ok, -1 otherwise.
|
||||||
@param ini Dictionary to modify.
|
|
||||||
@param entry Entry to modify (entry name)
|
If the given entry can be found in the dictionary, it is modified to
|
||||||
@param val New value to associate to the entry.
|
contain the provided value. If it cannot be found, the entry is created.
|
||||||
@return int 0 if Ok, -1 otherwise.
|
It is Ok to set val to NULL.
|
||||||
|
*/
|
||||||
If the given entry can be found in the dictionary, it is modified to
|
/*--------------------------------------------------------------------------*/
|
||||||
contain the provided value. If it cannot be found, the entry is created.
|
int iniparser_set(dictionary* ini, const char* entry, const char* val);
|
||||||
It is Ok to set val to NULL.
|
|
||||||
*/
|
/*-------------------------------------------------------------------------*/
|
||||||
/*--------------------------------------------------------------------------*/
|
/**
|
||||||
int iniparser_set(dictionary * ini, const char * entry, const char * val);
|
@brief Delete an entry in a dictionary
|
||||||
|
@param ini Dictionary to modify
|
||||||
|
@param entry Entry to delete (entry name)
|
||||||
/*-------------------------------------------------------------------------*/
|
|
||||||
/**
|
If the given entry can be found, it is deleted from the dictionary.
|
||||||
@brief Delete an entry in a dictionary
|
*/
|
||||||
@param ini Dictionary to modify
|
/*--------------------------------------------------------------------------*/
|
||||||
@param entry Entry to delete (entry name)
|
void iniparser_unset(dictionary* ini, const char* entry);
|
||||||
|
|
||||||
If the given entry can be found, it is deleted from the dictionary.
|
/*-------------------------------------------------------------------------*/
|
||||||
*/
|
/**
|
||||||
/*--------------------------------------------------------------------------*/
|
@brief Finds out if a given entry exists in a dictionary
|
||||||
void iniparser_unset(dictionary * ini, const char * entry);
|
@param ini Dictionary to search
|
||||||
|
@param entry Name of the entry to look for
|
||||||
/*-------------------------------------------------------------------------*/
|
@return integer 1 if entry exists, 0 otherwise
|
||||||
/**
|
|
||||||
@brief Finds out if a given entry exists in a dictionary
|
Finds out if a given entry exists in the dictionary. Since sections
|
||||||
@param ini Dictionary to search
|
are stored as keys with NULL associated values, this is the only way
|
||||||
@param entry Name of the entry to look for
|
of querying for the presence of sections in a dictionary.
|
||||||
@return integer 1 if entry exists, 0 otherwise
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
Finds out if a given entry exists in the dictionary. Since sections
|
int iniparser_find_entry(const dictionary* ini, const char* entry);
|
||||||
are stored as keys with NULL associated values, this is the only way
|
|
||||||
of querying for the presence of sections in a dictionary.
|
/*-------------------------------------------------------------------------*/
|
||||||
*/
|
/**
|
||||||
/*--------------------------------------------------------------------------*/
|
@brief Parse an ini file and return an allocated dictionary object
|
||||||
int iniparser_find_entry(const dictionary * ini, const char * entry) ;
|
@param ininame Name of the ini file to read.
|
||||||
|
@return Pointer to newly allocated dictionary
|
||||||
/*-------------------------------------------------------------------------*/
|
|
||||||
/**
|
This is the parser for ini files. This function is called, providing
|
||||||
@brief Parse an ini file and return an allocated dictionary object
|
the name of the file to be read. It returns a dictionary object that
|
||||||
@param ininame Name of the ini file to read.
|
should not be accessed directly, but through accessor functions
|
||||||
@return Pointer to newly allocated dictionary
|
instead.
|
||||||
|
|
||||||
This is the parser for ini files. This function is called, providing
|
Iff the value is a quoted string it supports some escape sequences:
|
||||||
the name of the file to be read. It returns a dictionary object that
|
|
||||||
should not be accessed directly, but through accessor functions
|
- \" or ' : the quote character
|
||||||
instead.
|
(e.g. 'String with "Quotes"' or "String with 'Quotes'")
|
||||||
|
- \ : the backslash character (e.g. "C:\tmp")
|
||||||
Iff the value is a quoted string it supports some escape sequences:
|
|
||||||
|
Escape sequences always start with a backslash. Additional escape sequences
|
||||||
- \" or ' : the quote character
|
might be added in the future. Backslash characters must be escaped. Any other
|
||||||
(e.g. 'String with "Quotes"' or "String with 'Quotes'")
|
sequence then those outlined above is invalid and may lead to unpredictable
|
||||||
- \ : the backslash character (e.g. "C:\tmp")
|
results.
|
||||||
|
|
||||||
Escape sequences always start with a backslash. Additional escape sequences
|
The returned dictionary must be freed using iniparser_freedict().
|
||||||
might be added in the future. Backslash characters must be escaped. Any other
|
*/
|
||||||
sequence then those outlined above is invalid and may lead to unpredictable
|
/*--------------------------------------------------------------------------*/
|
||||||
results.
|
dictionary* iniparser_load(const char* ininame);
|
||||||
|
|
||||||
The returned dictionary must be freed using iniparser_freedict().
|
/*-------------------------------------------------------------------------*/
|
||||||
*/
|
/**
|
||||||
/*--------------------------------------------------------------------------*/
|
@brief Parse an ini file and return an allocated dictionary object
|
||||||
dictionary * iniparser_load(const char * ininame);
|
@param in File to read.
|
||||||
|
@param ininame Name of the ini file to read (only used for nicer error messages)
|
||||||
/*-------------------------------------------------------------------------*/
|
@return Pointer to newly allocated dictionary
|
||||||
/**
|
|
||||||
@brief Parse an ini file and return an allocated dictionary object
|
This is the parser for ini files. This function is called, providing
|
||||||
@param in File to read.
|
the file to be read. It returns a dictionary object that should not
|
||||||
@param ininame Name of the ini file to read (only used for nicer error messages)
|
be accessed directly, but through accessor functions instead.
|
||||||
@return Pointer to newly allocated dictionary
|
|
||||||
|
Iff the value is a quoted string it supports some escape sequences:
|
||||||
This is the parser for ini files. This function is called, providing
|
|
||||||
the file to be read. It returns a dictionary object that should not
|
- \" or ' : the quote character
|
||||||
be accessed directly, but through accessor functions instead.
|
(e.g. 'String with "Quotes"' or "String with 'Quotes'")
|
||||||
|
- \ : the backslash character (e.g. "C:\tmp")
|
||||||
Iff the value is a quoted string it supports some escape sequences:
|
|
||||||
|
Escape sequences always start with a backslash. Additional escape sequences
|
||||||
- \" or ' : the quote character
|
might be added in the future. Backslash characters must be escaped. Any other
|
||||||
(e.g. 'String with "Quotes"' or "String with 'Quotes'")
|
sequence then those outlined above is invalid and may lead to unpredictable
|
||||||
- \ : the backslash character (e.g. "C:\tmp")
|
results.
|
||||||
|
|
||||||
Escape sequences always start with a backslash. Additional escape sequences
|
The returned dictionary must be freed using iniparser_freedict().
|
||||||
might be added in the future. Backslash characters must be escaped. Any other
|
*/
|
||||||
sequence then those outlined above is invalid and may lead to unpredictable
|
/*--------------------------------------------------------------------------*/
|
||||||
results.
|
dictionary* iniparser_load_file(FILE* in, const char* ininame);
|
||||||
|
|
||||||
The returned dictionary must be freed using iniparser_freedict().
|
/*-------------------------------------------------------------------------*/
|
||||||
*/
|
/**
|
||||||
/*--------------------------------------------------------------------------*/
|
@brief Free all memory associated to an ini dictionary
|
||||||
dictionary * iniparser_load_file(FILE * in, const char * ininame);
|
@param d Dictionary to free
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
Free all memory associated to an ini dictionary.
|
||||||
/**
|
It is mandatory to call this function before the dictionary object
|
||||||
@brief Free all memory associated to an ini dictionary
|
gets out of the current context.
|
||||||
@param d Dictionary to free
|
*/
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
Free all memory associated to an ini dictionary.
|
void iniparser_freedict(dictionary* d);
|
||||||
It is mandatory to call this function before the dictionary object
|
|
||||||
gets out of the current context.
|
|
||||||
*/
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
void iniparser_freedict(dictionary * d);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#ifndef __PAFSTD__
|
#ifndef __PAFSTD__
|
||||||
#define __PAFSTD__
|
#define __PAFSTD__
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
#include <paf/std/stdlib.h>
|
#include <paf/std/stdlib.h>
|
||||||
#include <paf/std/string.h>
|
#include <paf/std/string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <inttypes.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define malloc sce_paf_malloc
|
#define malloc sce_paf_malloc
|
||||||
#define memcpy sce_paf_memcpy
|
#define memcpy sce_paf_memcpy
|
||||||
@ -18,20 +18,22 @@
|
|||||||
|
|
||||||
// _ctype_ isnt called that in scelibc, so just stub the functions that are needed
|
// _ctype_ isnt called that in scelibc, so just stub the functions that are needed
|
||||||
|
|
||||||
inline int _is_space(char c) {
|
inline int _is_space(char c)
|
||||||
return (c == ' ' || c == '\f' || c == '\n' ||
|
{
|
||||||
c == '\r' || c == '\t' || c == '\v');
|
return (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v');
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int _to_lower(int c) {
|
inline int _to_lower(int c)
|
||||||
if (c >= 'A' && c <= 'Z') {
|
{
|
||||||
return c + ('a' - 'A');
|
if (c >= 'A' && c <= 'Z') {
|
||||||
}
|
return c + ('a' - 'A');
|
||||||
return c;
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int _is_digit(int c) {
|
inline int _is_digit(int c)
|
||||||
return (c >= '0' && c <= '9');
|
{
|
||||||
|
return (c >= '0' && c <= '9');
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef isspace
|
#undef isspace
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#include "pafinc.h"
|
|
||||||
#include <app_settings.h>
|
|
||||||
#include <psp2/kernel/clib.h>
|
|
||||||
#include <psp2/io/fcntl.h>
|
|
||||||
#include <psp2/sysmodule.h>
|
|
||||||
#include <psp2/kernel/modulemgr.h>
|
|
||||||
#include <psp2/appmgr.h>
|
|
||||||
|
|
||||||
#include "fios2.h"
|
#include "fios2.h"
|
||||||
|
#include "pafinc.h"
|
||||||
|
|
||||||
|
#include <app_settings.h>
|
||||||
#include <iniparser.h>
|
#include <iniparser.h>
|
||||||
|
#include <psp2/appmgr.h>
|
||||||
|
#include <psp2/io/fcntl.h>
|
||||||
|
#include <psp2/kernel/clib.h>
|
||||||
|
#include <psp2/kernel/modulemgr.h>
|
||||||
|
#include <psp2/sysmodule.h>
|
||||||
|
|
||||||
const char* g_iniPath = "ux0:data/isledecomp/isle/isle.ini";
|
const char* g_iniPath = "ux0:data/isledecomp/isle/isle.ini";
|
||||||
|
|
||||||
@ -16,177 +16,184 @@ paf::Plugin* g_configPlugin;
|
|||||||
sce::AppSettings* g_appSettings;
|
sce::AppSettings* g_appSettings;
|
||||||
sce::AppSettings::Interface* g_appSetIf;
|
sce::AppSettings::Interface* g_appSetIf;
|
||||||
|
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
paf::string m_base_path;
|
paf::string m_base_path;
|
||||||
paf::string m_cd_path;
|
paf::string m_cd_path;
|
||||||
paf::string m_save_path;
|
paf::string m_save_path;
|
||||||
int m_transition_type;
|
int m_transition_type;
|
||||||
int m_texture_quality;
|
int m_texture_quality;
|
||||||
int m_model_quality;
|
int m_model_quality;
|
||||||
int m_touch_scheme;
|
int m_touch_scheme;
|
||||||
bool m_wide_view_angle;
|
bool m_wide_view_angle;
|
||||||
bool m_music;
|
bool m_music;
|
||||||
bool m_3d_sound;
|
bool m_3d_sound;
|
||||||
bool m_haptic;
|
bool m_haptic;
|
||||||
bool m_draw_cursor;
|
bool m_draw_cursor;
|
||||||
bool m_texture_load;
|
bool m_texture_load;
|
||||||
paf::string m_texture_path;
|
paf::string m_texture_path;
|
||||||
float m_max_lod;
|
float m_max_lod;
|
||||||
int m_max_actors;
|
int m_max_actors;
|
||||||
float m_frame_delta;
|
float m_frame_delta;
|
||||||
|
|
||||||
void Init() {
|
void Init()
|
||||||
m_frame_delta = 10.0f;
|
{
|
||||||
m_transition_type = 3; // 3: Mosaic
|
m_frame_delta = 10.0f;
|
||||||
m_wide_view_angle = true;
|
m_transition_type = 3; // 3: Mosaic
|
||||||
m_music = true;
|
m_wide_view_angle = true;
|
||||||
m_3d_sound = true;
|
m_music = true;
|
||||||
m_haptic = true;
|
m_3d_sound = true;
|
||||||
m_touch_scheme = 2;
|
m_haptic = true;
|
||||||
m_texture_load = true;
|
m_touch_scheme = 2;
|
||||||
m_texture_path = "/textures/";
|
m_texture_load = true;
|
||||||
m_model_quality = 2;
|
m_texture_path = "/textures/";
|
||||||
m_texture_quality = 1;
|
m_model_quality = 2;
|
||||||
m_max_lod = 3.5f;
|
m_texture_quality = 1;
|
||||||
m_max_actors = 20;
|
m_max_lod = 3.5f;
|
||||||
}
|
m_max_actors = 20;
|
||||||
|
}
|
||||||
|
|
||||||
void LoadIni() {
|
void LoadIni()
|
||||||
dictionary* dict = iniparser_load(g_iniPath);
|
{
|
||||||
if (!dict) {
|
dictionary* dict = iniparser_load(g_iniPath);
|
||||||
dict = dictionary_new(0);
|
if (!dict) {
|
||||||
}
|
dict = dictionary_new(0);
|
||||||
|
}
|
||||||
|
|
||||||
#define GET_INT(x, name) x = iniparser_getint(dict, name, x)
|
#define GET_INT(x, name) x = iniparser_getint(dict, name, x)
|
||||||
#define GET_FLOAT(x, name) x = iniparser_getdouble(dict, name, x)
|
#define GET_FLOAT(x, name) x = iniparser_getdouble(dict, name, x)
|
||||||
#define GET_STRING(x, name) x = iniparser_getstring(dict, name, x.c_str()); sceClibPrintf("%s: %s\n", name, x.c_str())
|
#define GET_STRING(x, name) \
|
||||||
|
x = iniparser_getstring(dict, name, x.c_str()); \
|
||||||
|
sceClibPrintf("%s: %s\n", name, x.c_str())
|
||||||
#define GET_BOOLEAN(x, name) x = iniparser_getboolean(dict, name, x)
|
#define GET_BOOLEAN(x, name) x = iniparser_getboolean(dict, name, x)
|
||||||
|
|
||||||
GET_STRING(m_base_path, "isle:diskpath");
|
GET_STRING(m_base_path, "isle:diskpath");
|
||||||
GET_STRING(m_cd_path, "isle:cdpath");
|
GET_STRING(m_cd_path, "isle:cdpath");
|
||||||
GET_STRING(m_save_path, "isle:savepath");
|
GET_STRING(m_save_path, "isle:savepath");
|
||||||
|
|
||||||
//m_display_bit_depth = iniparser_getint(dict, "isle:Display Bit Depth", -1);
|
// m_display_bit_depth = iniparser_getint(dict, "isle:Display Bit Depth", -1);
|
||||||
//GET_BOOLEAN(m_flip_surfaces, "isle:Flip Surfaces");
|
// GET_BOOLEAN(m_flip_surfaces, "isle:Flip Surfaces");
|
||||||
//GET_BOOLEAN(m_full_screen, "isle:Full Screen");
|
// GET_BOOLEAN(m_full_screen, "isle:Full Screen");
|
||||||
//GET_BOOLEAN(m_exclusive_full_screen, "isle:Exclusive Full Screen");
|
// GET_BOOLEAN(m_exclusive_full_screen, "isle:Exclusive Full Screen");
|
||||||
GET_INT(m_transition_type, "isle:Transition Type");
|
GET_INT(m_transition_type, "isle:Transition Type");
|
||||||
GET_INT(m_touch_scheme, "isle:Touch Scheme");
|
GET_INT(m_touch_scheme, "isle:Touch Scheme");
|
||||||
//GET_BOOLEAN(m_3d_video_ram, "isle:Back Buffers in Video RAM");
|
// GET_BOOLEAN(m_3d_video_ram, "isle:Back Buffers in Video RAM");
|
||||||
GET_BOOLEAN(m_wide_view_angle, "isle:Wide View Angle");
|
GET_BOOLEAN(m_wide_view_angle, "isle:Wide View Angle");
|
||||||
GET_BOOLEAN(m_3d_sound, "isle:3DSound");
|
GET_BOOLEAN(m_3d_sound, "isle:3DSound");
|
||||||
GET_BOOLEAN(m_draw_cursor, "isle:Draw Cursor");
|
GET_BOOLEAN(m_draw_cursor, "isle:Draw Cursor");
|
||||||
GET_INT(m_model_quality, "isle:Island Quality");
|
GET_INT(m_model_quality, "isle:Island Quality");
|
||||||
GET_INT(m_texture_quality, "isle:Island Texture");
|
GET_INT(m_texture_quality, "isle:Island Texture");
|
||||||
//GET_BOOLEAN(m_use_joystick, "isle:UseJoystick");
|
// GET_BOOLEAN(m_use_joystick, "isle:UseJoystick");
|
||||||
GET_BOOLEAN(m_haptic, "isle:Haptic");
|
GET_BOOLEAN(m_haptic, "isle:Haptic");
|
||||||
GET_BOOLEAN(m_music, "isle:Music");
|
GET_BOOLEAN(m_music, "isle:Music");
|
||||||
//GET_INT(m_joystick_index, "isle:JoystickIndex");
|
// GET_INT(m_joystick_index, "isle:JoystickIndex");
|
||||||
GET_FLOAT(m_max_lod, "isle:Max LOD");
|
GET_FLOAT(m_max_lod, "isle:Max LOD");
|
||||||
GET_INT(m_max_actors, "isle:Max Allowed Extras");
|
GET_INT(m_max_actors, "isle:Max Allowed Extras");
|
||||||
GET_BOOLEAN(m_texture_load, "extensions:texture loader");
|
GET_BOOLEAN(m_texture_load, "extensions:texture loader");
|
||||||
GET_STRING(m_texture_path, "texture loader:texture path");
|
GET_STRING(m_texture_path, "texture loader:texture path");
|
||||||
//GET_INT(m_aspect_ratio, "isle:Aspect Ratio");
|
// GET_INT(m_aspect_ratio, "isle:Aspect Ratio");
|
||||||
//GET_INT(m_x_res, "isle:Horizontal Resolution");
|
// GET_INT(m_x_res, "isle:Horizontal Resolution");
|
||||||
//GET_INT(m_y_res, "isle:Vertical Resolution");
|
// GET_INT(m_y_res, "isle:Vertical Resolution");
|
||||||
GET_FLOAT(m_frame_delta, "isle:Frame Delta");
|
GET_FLOAT(m_frame_delta, "isle:Frame Delta");
|
||||||
#undef GET_INT
|
#undef GET_INT
|
||||||
#undef GET_FLOAT
|
#undef GET_FLOAT
|
||||||
#undef GET_STRING
|
#undef GET_STRING
|
||||||
#undef GET_BOOLEAN
|
#undef GET_BOOLEAN
|
||||||
iniparser_freedict(dict);
|
iniparser_freedict(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SaveIni() {
|
bool SaveIni()
|
||||||
dictionary* dict = dictionary_new(0);
|
{
|
||||||
|
dictionary* dict = dictionary_new(0);
|
||||||
|
|
||||||
char buffer[128];
|
char buffer[128];
|
||||||
#define SetIniBool(NAME, VALUE) iniparser_set(dict, NAME, VALUE ? "true" : "false")
|
#define SetIniBool(NAME, VALUE) iniparser_set(dict, NAME, VALUE ? "true" : "false")
|
||||||
#define SetIniInt(NAME, VALUE) { \
|
#define SetIniInt(NAME, VALUE) \
|
||||||
sceClibPrintf(buffer, "%d", VALUE); \
|
{ \
|
||||||
iniparser_set(dict, NAME, buffer); \
|
sceClibPrintf(buffer, "%d", VALUE); \
|
||||||
}
|
iniparser_set(dict, NAME, buffer); \
|
||||||
#define SetIniFloat(NAME, VALUE) { \
|
}
|
||||||
sceClibPrintf(buffer, "%f", VALUE); \
|
#define SetIniFloat(NAME, VALUE) \
|
||||||
iniparser_set(dict, NAME, buffer); \
|
{ \
|
||||||
}
|
sceClibPrintf(buffer, "%f", VALUE); \
|
||||||
|
iniparser_set(dict, NAME, buffer); \
|
||||||
|
}
|
||||||
#define SetString(NAME, VALUE) iniparser_set(dict, NAME, VALUE)
|
#define SetString(NAME, VALUE) iniparser_set(dict, NAME, VALUE)
|
||||||
|
|
||||||
SetIniInt("isle:Display Bit Depth", 32);
|
SetIniInt("isle:Display Bit Depth", 32);
|
||||||
SetIniBool("isle:Flip Surfaces", false);
|
SetIniBool("isle:Flip Surfaces", false);
|
||||||
SetIniBool("isle:Full Screen", true);
|
SetIniBool("isle:Full Screen", true);
|
||||||
SetIniBool("isle:Exclusive Full Screen", true);
|
SetIniBool("isle:Exclusive Full Screen", true);
|
||||||
SetIniBool("isle:Wide View Angle", true); // option?
|
SetIniBool("isle:Wide View Angle", true); // option?
|
||||||
|
|
||||||
SetIniInt("isle:Transition Type", m_transition_type);
|
SetIniInt("isle:Transition Type", m_transition_type);
|
||||||
SetIniInt("isle:Touch Scheme", m_touch_scheme);
|
SetIniInt("isle:Touch Scheme", m_touch_scheme);
|
||||||
|
|
||||||
SetIniBool("isle:3DSound", m_3d_sound);
|
SetIniBool("isle:3DSound", m_3d_sound);
|
||||||
SetIniBool("isle:Music", m_music);
|
SetIniBool("isle:Music", m_music);
|
||||||
SetIniBool("isle:Haptic", m_haptic);
|
SetIniBool("isle:Haptic", m_haptic);
|
||||||
|
|
||||||
SetIniBool("isle:UseJoystick", true);
|
SetIniBool("isle:UseJoystick", true);
|
||||||
SetIniInt("isle:JoystickIndex", 0);
|
SetIniInt("isle:JoystickIndex", 0);
|
||||||
SetIniBool("isle:Draw Cursor", m_draw_cursor);
|
SetIniBool("isle:Draw Cursor", m_draw_cursor);
|
||||||
|
|
||||||
SetIniBool("extensions:texture loader", m_texture_load);
|
SetIniBool("extensions:texture loader", m_texture_load);
|
||||||
SetString("texture loader:texture path", m_texture_path.c_str());
|
SetString("texture loader:texture path", m_texture_path.c_str());
|
||||||
|
|
||||||
SetIniBool("isle:Back Buffers in Video RAM", true);
|
SetIniBool("isle:Back Buffers in Video RAM", true);
|
||||||
|
|
||||||
SetIniInt("isle:Island Quality", m_model_quality);
|
SetIniInt("isle:Island Quality", m_model_quality);
|
||||||
SetIniInt("isle:Island Texture", m_texture_quality);
|
SetIniInt("isle:Island Texture", m_texture_quality);
|
||||||
|
|
||||||
SetIniFloat("isle:Max LOD", m_max_lod);
|
SetIniFloat("isle:Max LOD", m_max_lod);
|
||||||
SetIniInt("isle:Max Allowed Extras", m_max_actors);
|
SetIniInt("isle:Max Allowed Extras", m_max_actors);
|
||||||
|
|
||||||
SetIniInt("isle:Aspect Ratio", 0);
|
SetIniInt("isle:Aspect Ratio", 0);
|
||||||
SetIniInt("isle:Horizontal Resolution", 640);
|
SetIniInt("isle:Horizontal Resolution", 640);
|
||||||
SetIniInt("isle:Vertical Resolution", 480);
|
SetIniInt("isle:Vertical Resolution", 480);
|
||||||
SetIniFloat("isle:Frame Delta", 10.0f);
|
SetIniFloat("isle:Frame Delta", 10.0f);
|
||||||
|
|
||||||
#undef SetIniBool
|
#undef SetIniBool
|
||||||
#undef SetIniInt
|
#undef SetIniInt
|
||||||
#undef SetIniFloat
|
#undef SetIniFloat
|
||||||
#undef SetString
|
#undef SetString
|
||||||
|
|
||||||
FILE* fd = fopen(g_iniPath, "w");
|
FILE* fd = fopen(g_iniPath, "w");
|
||||||
if(fd) {
|
if (fd) {
|
||||||
iniparser_dump_ini(dict, fd);
|
iniparser_dump_ini(dict, fd);
|
||||||
}
|
}
|
||||||
iniparser_freedict(dict);
|
iniparser_freedict(dict);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToSettings(sce::AppSettings* appSettings) {
|
void ToSettings(sce::AppSettings* appSettings)
|
||||||
appSettings->SetString("data_path", this->m_base_path.c_str());
|
{
|
||||||
appSettings->SetString("save_path", this->m_save_path.c_str());
|
appSettings->SetString("data_path", this->m_base_path.c_str());
|
||||||
}
|
appSettings->SetString("save_path", this->m_save_path.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void FromSettings(sce::AppSettings* appSettings) {
|
void FromSettings(sce::AppSettings* appSettings) {}
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Config g_config;
|
Config g_config;
|
||||||
|
|
||||||
paf::Plugin* load_config_plugin(paf::Framework* paf_fw) {
|
paf::Plugin* load_config_plugin(paf::Framework* paf_fw)
|
||||||
paf::Plugin::InitParam pluginParam;
|
{
|
||||||
pluginParam.name = "config_plugin";
|
paf::Plugin::InitParam pluginParam;
|
||||||
pluginParam.caller_name = "__main__";
|
pluginParam.name = "config_plugin";
|
||||||
pluginParam.resource_file = "app0:/config_plugin.rco";
|
pluginParam.caller_name = "__main__";
|
||||||
pluginParam.init_func = NULL;
|
pluginParam.resource_file = "app0:/config_plugin.rco";
|
||||||
pluginParam.start_func = NULL;
|
pluginParam.init_func = NULL;
|
||||||
pluginParam.stop_func = NULL;
|
pluginParam.start_func = NULL;
|
||||||
pluginParam.exit_func = NULL;
|
pluginParam.stop_func = NULL;
|
||||||
paf::Plugin::LoadSync(pluginParam);
|
pluginParam.exit_func = NULL;
|
||||||
return paf_fw->FindPlugin("config_plugin");
|
paf::Plugin::LoadSync(pluginParam);
|
||||||
|
return paf_fw->FindPlugin("config_plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_app_settings_plugin() {
|
int load_app_settings_plugin()
|
||||||
paf::Plugin::InitParam pluginParam;
|
{
|
||||||
|
paf::Plugin::InitParam pluginParam;
|
||||||
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_BXCE);
|
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_BXCE);
|
||||||
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_INI_FILE_PROCESSOR);
|
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_INI_FILE_PROCESSOR);
|
||||||
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_COMMON_GUI_DIALOG);
|
sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_COMMON_GUI_DIALOG);
|
||||||
@ -201,102 +208,102 @@ int load_app_settings_plugin() {
|
|||||||
pluginParam.exit_func = sce::AppSettings::PluginExitCB;
|
pluginParam.exit_func = sce::AppSettings::PluginExitCB;
|
||||||
pluginParam.module_file = "vs0:vsh/common/app_settings.suprx";
|
pluginParam.module_file = "vs0:vsh/common/app_settings.suprx";
|
||||||
pluginParam.draw_priority = 0x96;
|
pluginParam.draw_priority = 0x96;
|
||||||
paf::Plugin::LoadSync(pluginParam);
|
paf::Plugin::LoadSync(pluginParam);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool do_launch = false;
|
bool do_launch = false;
|
||||||
|
|
||||||
void save_and_exit() {
|
void save_and_exit()
|
||||||
g_config.FromSettings(g_appSettings);
|
|
||||||
g_config.SaveIni();
|
|
||||||
g_fw->RequestShutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
void save_and_launch() {
|
|
||||||
g_config.FromSettings(g_appSettings);
|
|
||||||
g_config.SaveIni();
|
|
||||||
g_fw->RequestShutdown();
|
|
||||||
do_launch = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CBOnStartPageTransition(const char *elementId, int32_t type)
|
|
||||||
{
|
{
|
||||||
|
g_config.FromSettings(g_appSettings);
|
||||||
|
g_config.SaveIni();
|
||||||
|
g_fw->RequestShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBOnPageActivate(const char *elementId, int32_t type)
|
void save_and_launch()
|
||||||
{
|
{
|
||||||
|
g_config.FromSettings(g_appSettings);
|
||||||
|
g_config.SaveIni();
|
||||||
|
g_fw->RequestShutdown();
|
||||||
|
do_launch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBOnPageDeactivate(const char *elementId, int32_t type)
|
void CBOnStartPageTransition(const char* elementId, int32_t type)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnCheckVisible(const char *elementId, bool *pIsVisible)
|
void CBOnPageActivate(const char* elementId, int32_t type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBOnPageDeactivate(const char* elementId, int32_t type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t CBOnCheckVisible(const char* elementId, bool* pIsVisible)
|
||||||
{
|
{
|
||||||
*pIsVisible = true;
|
*pIsVisible = true;
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnPreCreate(const char *elementId, sce::AppSettings::Element *element)
|
int32_t CBOnPreCreate(const char* elementId, sce::AppSettings::Element* element)
|
||||||
{
|
{
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnPostCreate(const char *elementId, paf::ui::Widget *widget)
|
int32_t CBOnPostCreate(const char* elementId, paf::ui::Widget* widget)
|
||||||
{
|
{
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnPress(const char *elementId, const char *newValue)
|
int32_t CBOnPress(const char* elementId, const char* newValue)
|
||||||
{
|
{
|
||||||
if(sce_paf_strcmp(elementId, "save_exit_button") == 0) {
|
if (sce_paf_strcmp(elementId, "save_exit_button") == 0) {
|
||||||
save_and_exit();
|
save_and_exit();
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sce_paf_strcmp(elementId, "save_launch_button") == 0) {
|
if (sce_paf_strcmp(elementId, "save_launch_button") == 0) {
|
||||||
save_and_launch();
|
save_and_launch();
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sceClibPrintf("OnPress %s %s\n", elementId, newValue);
|
sceClibPrintf("OnPress %s %s\n", elementId, newValue);
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnPress2(const char *elementId, const char *newValue)
|
int32_t CBOnPress2(const char* elementId, const char* newValue)
|
||||||
{
|
{
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBOnTerm(int32_t result)
|
void CBOnTerm(int32_t result)
|
||||||
{
|
{
|
||||||
sceKernelExitProcess(0);
|
sceKernelExitProcess(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t *CBOnGetString(const char *elementId)
|
const wchar_t* CBOnGetString(const char* elementId)
|
||||||
{
|
{
|
||||||
wchar_t* res = g_configPlugin->GetString(elementId);
|
wchar_t* res = g_configPlugin->GetString(elementId);
|
||||||
if(res[0] != 0) {
|
if (res[0] != 0) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return L"unknown string";
|
return L"unknown string";
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CBOnGetSurface(paf::graph::Surface **surf, const char *elementId)
|
int32_t CBOnGetSurface(paf::graph::Surface** surf, const char* elementId)
|
||||||
{
|
{
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void open_settings() {
|
void open_settings()
|
||||||
g_config.Init();
|
{
|
||||||
g_config.LoadIni();
|
g_config.Init();
|
||||||
g_config.ToSettings(g_appSettings);
|
g_config.LoadIni();
|
||||||
|
g_config.ToSettings(g_appSettings);
|
||||||
|
|
||||||
sce::AppSettings::InterfaceCallbacks ifCb;
|
sce::AppSettings::InterfaceCallbacks ifCb;
|
||||||
ifCb.onStartPageTransitionCb = CBOnStartPageTransition;
|
ifCb.onStartPageTransitionCb = CBOnStartPageTransition;
|
||||||
ifCb.onPageActivateCb = CBOnPageActivate;
|
ifCb.onPageActivateCb = CBOnPageActivate;
|
||||||
ifCb.onPageDeactivateCb = CBOnPageDeactivate;
|
ifCb.onPageDeactivateCb = CBOnPageDeactivate;
|
||||||
@ -306,22 +313,21 @@ void open_settings() {
|
|||||||
ifCb.onPressCb = CBOnPress;
|
ifCb.onPressCb = CBOnPress;
|
||||||
ifCb.onPressCb2 = CBOnPress2;
|
ifCb.onPressCb2 = CBOnPress2;
|
||||||
ifCb.onTermCb = CBOnTerm;
|
ifCb.onTermCb = CBOnTerm;
|
||||||
ifCb.onGetStringCb = (sce::AppSettings::InterfaceCallbacks::GetStringCallback)CBOnGetString;
|
ifCb.onGetStringCb = (sce::AppSettings::InterfaceCallbacks::GetStringCallback) CBOnGetString;
|
||||||
ifCb.onGetSurfaceCb = CBOnGetSurface;
|
ifCb.onGetSurfaceCb = CBOnGetSurface;
|
||||||
|
|
||||||
paf::wstring msg_save_exit(g_configPlugin->GetString("msg_save_exit"));
|
paf::wstring msg_save_exit(g_configPlugin->GetString("msg_save_exit"));
|
||||||
paf::wstring msg_save_launch(g_configPlugin->GetString("msg_save_launch"));
|
paf::wstring msg_save_launch(g_configPlugin->GetString("msg_save_launch"));
|
||||||
paf::wstring msg_exit(g_configPlugin->GetString("msg_exit"));
|
paf::wstring msg_exit(g_configPlugin->GetString("msg_exit"));
|
||||||
|
|
||||||
paf::Plugin* appSetPlug = paf::Plugin::Find("app_settings_plugin");
|
paf::Plugin* appSetPlug = paf::Plugin::Find("app_settings_plugin");
|
||||||
g_appSetIf = (sce::AppSettings::Interface *)appSetPlug->GetInterface(1);
|
g_appSetIf = (sce::AppSettings::Interface*) appSetPlug->GetInterface(1);
|
||||||
g_appSetIf->Show(&ifCb);
|
g_appSetIf->Show(&ifCb);
|
||||||
g_appSetIf->AddFooterButton("save_exit_button", &msg_save_exit, 1);
|
g_appSetIf->AddFooterButton("save_exit_button", &msg_save_exit, 1);
|
||||||
g_appSetIf->AddFooterButton("save_launch_button", &msg_save_launch, 2);
|
g_appSetIf->AddFooterButton("save_launch_button", &msg_save_launch, 2);
|
||||||
g_appSetIf->ShowFooter();
|
g_appSetIf->ShowFooter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MAX_PATH_LENGTH 256
|
#define MAX_PATH_LENGTH 256
|
||||||
|
|
||||||
static int64_t g_OpStorage[SCE_FIOS_OP_STORAGE_SIZE(64, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
static int64_t g_OpStorage[SCE_FIOS_OP_STORAGE_SIZE(64, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
||||||
@ -329,9 +335,10 @@ static int64_t g_ChunkStorage[SCE_FIOS_CHUNK_STORAGE_SIZE(1024) / sizeof(int64_t
|
|||||||
static int64_t g_FHStorage[SCE_FIOS_FH_STORAGE_SIZE(1024, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
static int64_t g_FHStorage[SCE_FIOS_FH_STORAGE_SIZE(1024, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
||||||
static int64_t g_DHStorage[SCE_FIOS_DH_STORAGE_SIZE(32, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
static int64_t g_DHStorage[SCE_FIOS_DH_STORAGE_SIZE(32, MAX_PATH_LENGTH) / sizeof(int64_t) + 1];
|
||||||
|
|
||||||
void init_fios2() {
|
void init_fios2()
|
||||||
sceSysmoduleLoadModule(SCE_SYSMODULE_FIOS2);
|
{
|
||||||
SceFiosParams params = SCE_FIOS_PARAMS_INITIALIZER;
|
sceSysmoduleLoadModule(SCE_SYSMODULE_FIOS2);
|
||||||
|
SceFiosParams params = SCE_FIOS_PARAMS_INITIALIZER;
|
||||||
params.opStorage.pPtr = g_OpStorage;
|
params.opStorage.pPtr = g_OpStorage;
|
||||||
params.opStorage.length = sizeof(g_OpStorage);
|
params.opStorage.length = sizeof(g_OpStorage);
|
||||||
params.chunkStorage.pPtr = g_ChunkStorage;
|
params.chunkStorage.pPtr = g_ChunkStorage;
|
||||||
@ -349,47 +356,48 @@ void init_fios2() {
|
|||||||
params.threadPriority[SCE_FIOS_IO_THREAD] = 64;
|
params.threadPriority[SCE_FIOS_IO_THREAD] = 64;
|
||||||
params.threadPriority[SCE_FIOS_CALLBACK_THREAD] = 191;
|
params.threadPriority[SCE_FIOS_CALLBACK_THREAD] = 191;
|
||||||
params.threadPriority[SCE_FIOS_DECOMPRESSOR_THREAD] = 191;
|
params.threadPriority[SCE_FIOS_DECOMPRESSOR_THREAD] = 191;
|
||||||
int ret = sceFiosInitialize(¶ms);
|
int ret = sceFiosInitialize(¶ms);
|
||||||
if(ret < 0) {
|
if (ret < 0) {
|
||||||
sceClibPrintf("sceFiosInitialize: %08x\n", ret);
|
sceClibPrintf("sceFiosInitialize: %08x\n", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int paf_main(void) {
|
int paf_main(void)
|
||||||
init_fios2();
|
{
|
||||||
|
init_fios2();
|
||||||
|
|
||||||
paf::Framework::InitParam fwParam;
|
paf::Framework::InitParam fwParam;
|
||||||
fwParam.mode = paf::Framework::Mode_Normal;
|
fwParam.mode = paf::Framework::Mode_Normal;
|
||||||
|
|
||||||
paf::Framework* paf_fw = new paf::Framework(fwParam);
|
paf::Framework* paf_fw = new paf::Framework(fwParam);
|
||||||
g_fw = paf_fw;
|
g_fw = paf_fw;
|
||||||
|
|
||||||
paf_fw->LoadCommonResourceSync();
|
paf_fw->LoadCommonResourceSync();
|
||||||
load_app_settings_plugin();
|
load_app_settings_plugin();
|
||||||
paf::Plugin* configPlugin = load_config_plugin(paf_fw);
|
paf::Plugin* configPlugin = load_config_plugin(paf_fw);
|
||||||
g_configPlugin = configPlugin;
|
g_configPlugin = configPlugin;
|
||||||
configPlugin->SetLocale(Locale_EN);
|
configPlugin->SetLocale(Locale_EN);
|
||||||
|
|
||||||
size_t fileSize = 0;
|
size_t fileSize = 0;
|
||||||
const char *mimeType = nullptr;
|
const char* mimeType = nullptr;
|
||||||
auto settingsXmlFile = configPlugin->GetResource()->GetFile("settings.xml", &fileSize, &mimeType);
|
auto settingsXmlFile = configPlugin->GetResource()->GetFile("settings.xml", &fileSize, &mimeType);
|
||||||
|
|
||||||
sce::AppSettings::InitParam settingsParam;
|
sce::AppSettings::InitParam settingsParam;
|
||||||
settingsParam.xml_file = settingsXmlFile;
|
settingsParam.xml_file = settingsXmlFile;
|
||||||
settingsParam.alloc_cb = sce_paf_malloc;
|
settingsParam.alloc_cb = sce_paf_malloc;
|
||||||
settingsParam.free_cb = sce_paf_free;
|
settingsParam.free_cb = sce_paf_free;
|
||||||
settingsParam.realloc_cb = sce_paf_realloc;
|
settingsParam.realloc_cb = sce_paf_realloc;
|
||||||
settingsParam.safemem_offset = 0;
|
settingsParam.safemem_offset = 0;
|
||||||
settingsParam.safemem_size = 0x400;
|
settingsParam.safemem_size = 0x400;
|
||||||
|
|
||||||
sce::AppSettings::GetInstance(settingsParam, &g_appSettings);
|
sce::AppSettings::GetInstance(settingsParam, &g_appSettings);
|
||||||
g_appSettings->Initialize();
|
g_appSettings->Initialize();
|
||||||
|
|
||||||
open_settings();
|
open_settings();
|
||||||
paf_fw->Run();
|
paf_fw->Run();
|
||||||
|
|
||||||
if(do_launch) {
|
if (do_launch) {
|
||||||
sceAppMgrLoadExec("app0:/eboot.bin", NULL, NULL);
|
sceAppMgrLoadExec("app0:/eboot.bin", NULL, NULL);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "pafinc.h"
|
#include "pafinc.h"
|
||||||
|
|
||||||
#include <psp2/kernel/clib.h>
|
#include <psp2/kernel/clib.h>
|
||||||
#include <psp2/kernel/modulemgr.h>
|
#include <psp2/kernel/modulemgr.h>
|
||||||
#include <psp2/kernel/processmgr.h>
|
#include <psp2/kernel/processmgr.h>
|
||||||
|
|||||||
@ -503,12 +503,14 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
|
|||||||
|
|
||||||
#ifdef __vita__
|
#ifdef __vita__
|
||||||
// reject back touch panel
|
// reject back touch panel
|
||||||
switch(event->type) {
|
switch (event->type) {
|
||||||
case SDL_EVENT_FINGER_MOTION:
|
case SDL_EVENT_FINGER_MOTION:
|
||||||
case SDL_EVENT_FINGER_DOWN:
|
case SDL_EVENT_FINGER_DOWN:
|
||||||
case SDL_EVENT_FINGER_UP:
|
case SDL_EVENT_FINGER_UP:
|
||||||
case SDL_EVENT_FINGER_CANCELED:
|
case SDL_EVENT_FINGER_CANCELED:
|
||||||
if(event->tfinger.touchID == 2) return SDL_APP_CONTINUE;
|
if (event->tfinger.touchID == 2) {
|
||||||
|
return SDL_APP_CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -685,8 +685,12 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height, DWORD msaaSamples)
|
|||||||
m_virtualHeight = height;
|
m_virtualHeight = height;
|
||||||
|
|
||||||
SceGxmMultisampleMode msaaMode = SCE_GXM_MULTISAMPLE_NONE;
|
SceGxmMultisampleMode msaaMode = SCE_GXM_MULTISAMPLE_NONE;
|
||||||
if(msaaSamples == 2) msaaMode = SCE_GXM_MULTISAMPLE_2X;
|
if (msaaSamples == 2) {
|
||||||
if(msaaSamples == 4) msaaMode = SCE_GXM_MULTISAMPLE_4X;
|
msaaMode = SCE_GXM_MULTISAMPLE_2X;
|
||||||
|
}
|
||||||
|
if (msaaSamples == 4) {
|
||||||
|
msaaMode = SCE_GXM_MULTISAMPLE_4X;
|
||||||
|
}
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
if (!gxm) {
|
if (!gxm) {
|
||||||
@ -944,27 +948,30 @@ void GXMRenderer::DeferredDelete(int index)
|
|||||||
this->m_buffers_delete[index].clear();
|
this->m_buffers_delete[index].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int calculateMipLevels(int width, int height) {
|
static int calculateMipLevels(int width, int height)
|
||||||
if (width <= 0 || height <= 0) {
|
{
|
||||||
return 1;
|
if (width <= 0 || height <= 0) {
|
||||||
}
|
return 1;
|
||||||
int maxDim = (width > height) ? width : height;
|
}
|
||||||
return floor(log2(maxDim)) + 1;
|
int maxDim = (width > height) ? width : height;
|
||||||
|
return floor(log2(maxDim)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nextPowerOf2(int n) {
|
static int nextPowerOf2(int n)
|
||||||
if (n <= 0) return 1;
|
{
|
||||||
n--;
|
if (n <= 0) {
|
||||||
n |= n >> 1;
|
return 1;
|
||||||
n |= n >> 2;
|
}
|
||||||
n |= n >> 4;
|
n--;
|
||||||
n |= n >> 8;
|
n |= n >> 1;
|
||||||
n |= n >> 16;
|
n |= n >> 2;
|
||||||
n++;
|
n |= n >> 4;
|
||||||
return n;
|
n |= n >> 8;
|
||||||
|
n |= n >> 16;
|
||||||
|
n++;
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void convertTextureMetadata(
|
static void convertTextureMetadata(
|
||||||
SDL_Surface* surface,
|
SDL_Surface* surface,
|
||||||
bool isUi,
|
bool isUi,
|
||||||
@ -988,8 +995,8 @@ static void convertTextureMetadata(
|
|||||||
*textureAlignment = SCE_GXM_PALETTE_ALIGNMENT;
|
*textureAlignment = SCE_GXM_PALETTE_ALIGNMENT;
|
||||||
bytesPerPixel = 1;
|
bytesPerPixel = 1;
|
||||||
if (!isUi) {
|
if (!isUi) {
|
||||||
*mipLevels = calculateMipLevels(surface->w, surface->h);
|
*mipLevels = calculateMipLevels(surface->w, surface->h);
|
||||||
}
|
}
|
||||||
paletteSize = 256 * 4; // palette
|
paletteSize = 256 * 4; // palette
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1016,24 +1023,24 @@ static void convertTextureMetadata(
|
|||||||
*mipLevels = 1; // look weird right now
|
*mipLevels = 1; // look weird right now
|
||||||
|
|
||||||
size_t totalSize = 0;
|
size_t totalSize = 0;
|
||||||
int currentW = surface->w;
|
int currentW = surface->w;
|
||||||
int currentH = surface->h;
|
int currentH = surface->h;
|
||||||
|
|
||||||
// top mip
|
// top mip
|
||||||
totalSize += (ALIGN(currentW, 8) * currentH) * bytesPerPixel;
|
totalSize += (ALIGN(currentW, 8) * currentH) * bytesPerPixel;
|
||||||
|
|
||||||
for (size_t i = 1; i < *mipLevels; ++i) {
|
for (size_t i = 1; i < *mipLevels; ++i) {
|
||||||
currentW = currentW > 1 ? currentW / 2 : 1;
|
currentW = currentW > 1 ? currentW / 2 : 1;
|
||||||
currentH = currentH > 1 ? currentH / 2 : 1;
|
currentH = currentH > 1 ? currentH / 2 : 1;
|
||||||
int po2W = nextPowerOf2(currentW * 2);
|
int po2W = nextPowerOf2(currentW * 2);
|
||||||
int po2H = nextPowerOf2(currentH * 2);
|
int po2H = nextPowerOf2(currentH * 2);
|
||||||
if (po2W < 8) {
|
if (po2W < 8) {
|
||||||
po2W = 8;
|
po2W = 8;
|
||||||
}
|
}
|
||||||
totalSize += po2W * po2H * bytesPerPixel;
|
totalSize += po2W * po2H * bytesPerPixel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(paletteSize != 0) {
|
if (paletteSize != 0) {
|
||||||
int alignBytes = ALIGNMENT(totalSize, SCE_GXM_PALETTE_ALIGNMENT);
|
int alignBytes = ALIGNMENT(totalSize, SCE_GXM_PALETTE_ALIGNMENT);
|
||||||
totalSize += alignBytes;
|
totalSize += alignBytes;
|
||||||
*paletteOffset = totalSize;
|
*paletteOffset = totalSize;
|
||||||
@ -1043,7 +1050,8 @@ static void convertTextureMetadata(
|
|||||||
*textureSize = totalSize;
|
*textureSize = totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void copySurfaceToGxmARGB888(SDL_Surface* src, uint8_t* textureData, size_t dstStride, size_t mipLevels) {
|
void copySurfaceToGxmARGB888(SDL_Surface* src, uint8_t* textureData, size_t dstStride, size_t mipLevels)
|
||||||
|
{
|
||||||
uint8_t* currentLevelData = textureData;
|
uint8_t* currentLevelData = textureData;
|
||||||
uint32_t currentLevelWidth = src->w;
|
uint32_t currentLevelWidth = src->w;
|
||||||
uint32_t currentLevelHeight = src->h;
|
uint32_t currentLevelHeight = src->h;
|
||||||
@ -1052,7 +1060,7 @@ void copySurfaceToGxmARGB888(SDL_Surface* src, uint8_t* textureData, size_t dstS
|
|||||||
// copy top level mip (cant use transfer because this isnt gpu mapped)
|
// copy top level mip (cant use transfer because this isnt gpu mapped)
|
||||||
size_t topLevelStride = ALIGN(currentLevelWidth, 8) * bytesPerPixel;
|
size_t topLevelStride = ALIGN(currentLevelWidth, 8) * bytesPerPixel;
|
||||||
for (int y = 0; y < currentLevelHeight; y++) {
|
for (int y = 0; y < currentLevelHeight; y++) {
|
||||||
uint8_t* srcRow = (uint8_t*)src->pixels + (y * src->pitch);
|
uint8_t* srcRow = (uint8_t*) src->pixels + (y * src->pitch);
|
||||||
uint8_t* dstRow = textureData + (y * topLevelStride);
|
uint8_t* dstRow = textureData + (y * topLevelStride);
|
||||||
memcpy(dstRow, srcRow, currentLevelWidth * bytesPerPixel);
|
memcpy(dstRow, srcRow, currentLevelWidth * bytesPerPixel);
|
||||||
}
|
}
|
||||||
@ -1063,26 +1071,38 @@ void copySurfaceToGxmARGB888(SDL_Surface* src, uint8_t* textureData, size_t dstS
|
|||||||
uint8_t* nextLevelData = currentLevelData + (currentLevelSrcStride * currentLevelHeight);
|
uint8_t* nextLevelData = currentLevelData + (currentLevelSrcStride * currentLevelHeight);
|
||||||
|
|
||||||
sceGxmTransferDownscale(
|
sceGxmTransferDownscale(
|
||||||
SCE_GXM_TRANSFER_FORMAT_U8U8U8U8_ABGR, // src format
|
SCE_GXM_TRANSFER_FORMAT_U8U8U8U8_ABGR, // src format
|
||||||
currentLevelData, // src address
|
currentLevelData, // src address
|
||||||
0, 0, currentLevelWidth, currentLevelHeight, // x,y,w,h
|
0,
|
||||||
currentLevelSrcStride, // stride
|
0,
|
||||||
SCE_GXM_TRANSFER_FORMAT_U8U8U8U8_ABGR, // dst format
|
currentLevelWidth,
|
||||||
nextLevelData, // dst address
|
currentLevelHeight, // x,y,w,h
|
||||||
0, 0, // x,y
|
currentLevelSrcStride, // stride
|
||||||
currentLevelDestStride, // stride
|
SCE_GXM_TRANSFER_FORMAT_U8U8U8U8_ABGR, // dst format
|
||||||
NULL, // sync
|
nextLevelData, // dst address
|
||||||
SCE_GXM_TRANSFER_FRAGMENT_SYNC, // flag
|
0,
|
||||||
NULL // notification
|
0, // x,y
|
||||||
|
currentLevelDestStride, // stride
|
||||||
|
NULL, // sync
|
||||||
|
SCE_GXM_TRANSFER_FRAGMENT_SYNC, // flag
|
||||||
|
NULL // notification
|
||||||
);
|
);
|
||||||
|
|
||||||
currentLevelData = nextLevelData;
|
currentLevelData = nextLevelData;
|
||||||
currentLevelWidth = currentLevelWidth / 2;
|
currentLevelWidth = currentLevelWidth / 2;
|
||||||
currentLevelHeight = currentLevelHeight / 2;
|
currentLevelHeight = currentLevelHeight / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void copySurfaceToGxmIndexed8(DirectDrawSurfaceImpl* surface, SDL_Surface* src, uint8_t* textureData, size_t dstStride, uint8_t* paletteData, size_t mipLevels) {
|
void copySurfaceToGxmIndexed8(
|
||||||
|
DirectDrawSurfaceImpl* surface,
|
||||||
|
SDL_Surface* src,
|
||||||
|
uint8_t* textureData,
|
||||||
|
size_t dstStride,
|
||||||
|
uint8_t* paletteData,
|
||||||
|
size_t mipLevels
|
||||||
|
)
|
||||||
|
{
|
||||||
LPDIRECTDRAWPALETTE _palette;
|
LPDIRECTDRAWPALETTE _palette;
|
||||||
surface->GetPalette(&_palette);
|
surface->GetPalette(&_palette);
|
||||||
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
auto palette = static_cast<DirectDrawPaletteImpl*>(_palette);
|
||||||
@ -1098,7 +1118,7 @@ void copySurfaceToGxmIndexed8(DirectDrawSurfaceImpl* surface, SDL_Surface* src,
|
|||||||
// copy top level mip (cant use transfer because this isnt gpu mapped)
|
// copy top level mip (cant use transfer because this isnt gpu mapped)
|
||||||
size_t topLevelStride = ALIGN(currentLevelWidth, 8) * bytesPerPixel;
|
size_t topLevelStride = ALIGN(currentLevelWidth, 8) * bytesPerPixel;
|
||||||
for (int y = 0; y < currentLevelHeight; y++) {
|
for (int y = 0; y < currentLevelHeight; y++) {
|
||||||
uint8_t* srcRow = (uint8_t*)src->pixels + (y * src->pitch);
|
uint8_t* srcRow = (uint8_t*) src->pixels + (y * src->pitch);
|
||||||
uint8_t* dstRow = textureData + (y * topLevelStride);
|
uint8_t* dstRow = textureData + (y * topLevelStride);
|
||||||
memcpy(dstRow, srcRow, currentLevelWidth * bytesPerPixel);
|
memcpy(dstRow, srcRow, currentLevelWidth * bytesPerPixel);
|
||||||
}
|
}
|
||||||
@ -1109,28 +1129,38 @@ void copySurfaceToGxmIndexed8(DirectDrawSurfaceImpl* surface, SDL_Surface* src,
|
|||||||
uint8_t* nextLevelData = currentLevelData + (currentLevelSrcStride * currentLevelHeight);
|
uint8_t* nextLevelData = currentLevelData + (currentLevelSrcStride * currentLevelHeight);
|
||||||
|
|
||||||
sceGxmTransferDownscale(
|
sceGxmTransferDownscale(
|
||||||
SCE_GXM_TRANSFER_FORMAT_U8_R, // src format
|
SCE_GXM_TRANSFER_FORMAT_U8_R, // src format
|
||||||
currentLevelData, // src address
|
currentLevelData, // src address
|
||||||
0, 0, currentLevelWidth, currentLevelHeight, // x,y,w,h
|
0,
|
||||||
currentLevelSrcStride, // stride
|
0,
|
||||||
SCE_GXM_TRANSFER_FORMAT_U8_R, // dst format
|
currentLevelWidth,
|
||||||
nextLevelData, // dst address
|
currentLevelHeight, // x,y,w,h
|
||||||
0, 0, // x,y
|
currentLevelSrcStride, // stride
|
||||||
currentLevelDestStride, // stride
|
SCE_GXM_TRANSFER_FORMAT_U8_R, // dst format
|
||||||
NULL, // sync
|
nextLevelData, // dst address
|
||||||
SCE_GXM_TRANSFER_FRAGMENT_SYNC, // flag
|
0,
|
||||||
NULL // notification
|
0, // x,y
|
||||||
|
currentLevelDestStride, // stride
|
||||||
|
NULL, // sync
|
||||||
|
SCE_GXM_TRANSFER_FRAGMENT_SYNC, // flag
|
||||||
|
NULL // notification
|
||||||
);
|
);
|
||||||
|
|
||||||
currentLevelData = nextLevelData;
|
currentLevelData = nextLevelData;
|
||||||
currentLevelWidth = currentLevelWidth / 2;
|
currentLevelWidth = currentLevelWidth / 2;
|
||||||
currentLevelHeight = currentLevelHeight / 2;
|
currentLevelHeight = currentLevelHeight / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
palette->Release();
|
palette->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void copySurfaceToGxm(DirectDrawSurfaceImpl* surface, uint8_t* textureData, size_t dstStride, size_t paletteOffset, size_t mipLevels)
|
void copySurfaceToGxm(
|
||||||
|
DirectDrawSurfaceImpl* surface,
|
||||||
|
uint8_t* textureData,
|
||||||
|
size_t dstStride,
|
||||||
|
size_t paletteOffset,
|
||||||
|
size_t mipLevels
|
||||||
|
)
|
||||||
{
|
{
|
||||||
SDL_Surface* src = surface->m_surface;
|
SDL_Surface* src = surface->m_surface;
|
||||||
|
|
||||||
@ -1140,7 +1170,7 @@ void copySurfaceToGxm(DirectDrawSurfaceImpl* surface, uint8_t* textureData, size
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_PIXELFORMAT_INDEX8: {
|
case SDL_PIXELFORMAT_INDEX8: {
|
||||||
copySurfaceToGxmIndexed8(surface, src, textureData, dstStride, textureData+paletteOffset, mipLevels);
|
copySurfaceToGxmIndexed8(surface, src, textureData, dstStride, textureData + paletteOffset, mipLevels);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -1211,11 +1241,19 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture, bool isUi, float
|
|||||||
);
|
);
|
||||||
|
|
||||||
// allocate gpu memory
|
// allocate gpu memory
|
||||||
uint8_t* textureData = (uint8_t*)gxm->alloc(textureSize, textureAlignment);
|
uint8_t* textureData = (uint8_t*) gxm->alloc(textureSize, textureAlignment);
|
||||||
copySurfaceToGxm(surface, (uint8_t*) textureData, textureStride, paletteOffset, mipLevels);
|
copySurfaceToGxm(surface, (uint8_t*) textureData, textureStride, paletteOffset, mipLevels);
|
||||||
|
|
||||||
SceGxmTexture gxmTexture;
|
SceGxmTexture gxmTexture;
|
||||||
SCE_ERR(sceGxmTextureInitLinear, &gxmTexture, textureData, gxmTextureFormat, textureWidth, textureHeight, mipLevels);
|
SCE_ERR(
|
||||||
|
sceGxmTextureInitLinear,
|
||||||
|
&gxmTexture,
|
||||||
|
textureData,
|
||||||
|
gxmTextureFormat,
|
||||||
|
textureWidth,
|
||||||
|
textureHeight,
|
||||||
|
mipLevels
|
||||||
|
);
|
||||||
if (isUi) {
|
if (isUi) {
|
||||||
sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_POINT);
|
sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_POINT);
|
||||||
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_POINT);
|
sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_POINT);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user