Remove cheevos stuff from coro.h; add macros to increase readability

This commit is contained in:
leiradel 2018-01-30 17:47:20 +00:00
parent d3d4c5740c
commit 8147e6f31c
2 changed files with 797 additions and 786 deletions

View File

@ -2765,6 +2765,43 @@ cheevos_console_t cheevos_get_console(void)
/*#undef CORO_YIELD
#define CORO_YIELD()*/
typedef struct
{
/* variables used in the co-routine */
char badge_name[16];
char url[256];
char badge_basepath[PATH_MAX_LENGTH];
char badge_fullpath[PATH_MAX_LENGTH];
unsigned char hash[16];
bool round;
unsigned gameid;
unsigned i;
unsigned j;
unsigned k;
size_t bytes;
size_t count;
size_t offset;
size_t len;
size_t size;
MD5_CTX md5;
cheevos_nes_header_t header;
retro_time_t t0;
struct retro_system_info sysinfo;
void *data;
char *json;
const char *path;
const char *ext;
intfstream_t *stream;
cheevo_t *cheevo;
settings_t *settings;
struct http_connection_t *conn;
struct http_t *http;
const cheevo_t *cheevo_end;
/* co-routine required fields */
CORO_FIELDS
} coro_t;
enum
{
/* Negative values because CORO_SUB generates positive values */
@ -2835,13 +2872,8 @@ static int cheevos_iterate(coro_t *coro)
{GENERIC_MD5, "Generic (plain content)", NULL}
};
{
CORO_again: ;
/* Use at the beginning of the coroutine,
* you must have declared a variable coro_t* coro */
switch (coro->step)
{
case CORO_BEGIN:
CORO_ENTER();
cheevos_locals.addrs_patched = false;
coro->settings = config_get_ptr();
@ -3107,7 +3139,7 @@ found:
* Input CHEEVOS_VAR_INFO the content info
* Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found
*************************************************************************/
case SNES_MD5:
CORO_SUB(SNES_MD5)
MD5_Init(&coro->md5);
@ -3142,7 +3174,7 @@ found:
* Input CHEEVOS_VAR_INFO the content info
* Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found
*************************************************************************/
case GENESIS_MD5:
CORO_SUB(GENESIS_MD5)
MD5_Init(&coro->md5);
@ -3172,7 +3204,7 @@ found:
* Input CHEEVOS_VAR_INFO the content info
* Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found
*************************************************************************/
case LYNX_MD5:
CORO_SUB(LYNX_MD5)
if (coro->len < 0x0240)
{
@ -3194,7 +3226,7 @@ found:
* Input CHEEVOS_VAR_INFO the content info
* Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found
*************************************************************************/
case NES_MD5:
CORO_SUB(NES_MD5)
/* Note about the references to the FCEU emulator below. There is no
* core-specific code in this function, it's rather Retro Achievements
@ -3260,7 +3292,7 @@ found:
* Input CHEEVOS_VAR_INFO the content info
* Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found
*************************************************************************/
case GENERIC_MD5:
CORO_SUB(GENERIC_MD5)
MD5_Init(&coro->md5);
@ -3280,7 +3312,7 @@ found:
* Inputs CHEEVOS_VAR_INFO, CHEEVOS_VAR_OFFSET, CHEEVOS_VAR_COUNT
* Outputs CHEEVOS_VAR_MD5, CHEEVOS_VAR_COUNT
*************************************************************************/
case EVAL_MD5:
CORO_SUB(EVAL_MD5)
if (coro->count == 0)
coro->count = coro->len;
@ -3302,7 +3334,7 @@ found:
* Inputs CHEEVOS_VAR_OFFSET, CHEEVOS_VAR_COUNT
* Outputs CHEEVOS_VAR_MD5
*************************************************************************/
case FILL_MD5:
CORO_SUB(FILL_MD5)
{
char buffer[4096];
@ -3327,7 +3359,7 @@ found:
* Inputs coro->hash
* Outputs CHEEVOS_VAR_GAMEID
*************************************************************************/
case GET_GAMEID:
CORO_SUB(GET_GAMEID)
{
char gameid[16];
@ -3381,7 +3413,7 @@ found:
* Inputs CHEEVOS_VAR_GAMEID
* Outputs CHEEVOS_VAR_JSON
*************************************************************************/
case GET_CHEEVOS:
CORO_SUB(GET_CHEEVOS)
CORO_GOSUB(LOGIN);
@ -3413,7 +3445,7 @@ found:
* Inputs CHEEVOS_VAR_GAMEID
* Outputs CHEEVOS_VAR_JSON
*************************************************************************/
case GET_BADGES:
CORO_SUB(GET_BADGES)
badges_ctx = new_badges_ctx;
@ -3486,7 +3518,7 @@ found:
/**************************************************************************
* Info Logs in the user at Retro Achievements
*************************************************************************/
case LOGIN:
CORO_SUB(LOGIN)
if (cheevos_locals.token[0])
CORO_RET();
@ -3561,7 +3593,7 @@ found:
/**************************************************************************
* Info Pauses execution for five seconds
*************************************************************************/
case DELAY:
CORO_SUB(DELAY)
{
retro_time_t t1;
@ -3581,7 +3613,7 @@ found:
* Inputs CHEEVOS_VAR_URL
* Outputs CHEEVOS_VAR_JSON
*************************************************************************/
case HTTP_GET:
CORO_SUB(HTTP_GET)
for (coro->k = 0; coro->k < 5; coro->k++)
{
@ -3656,7 +3688,7 @@ found:
* Inputs CHEEVOS_VAR_GAMEID
* Outputs
*************************************************************************/
case DEACTIVATE:
CORO_SUB(DEACTIVATE)
#ifndef CHEEVOS_DONT_DEACTIVATE
CORO_GOSUB(LOGIN);
@ -3727,7 +3759,7 @@ found:
* Inputs CHEEVOS_VAR_GAMEID
* Outputs
*************************************************************************/
case PLAYING:
CORO_SUB(PLAYING)
snprintf(
coro->url, sizeof(coro->url),
@ -3756,9 +3788,7 @@ found:
RARCH_LOG("[CHEEVOS]: posted playing activity.\n");
CORO_RET();
}
}
return 0;
CORO_LEAVE();
}
static void cheevos_task_handler(retro_task_t *task)
@ -3811,7 +3841,7 @@ bool cheevos_load(const void *data)
return false;
}
CORO_SETUP(coro);
CORO_SETUP();
info = (const struct retro_game_info*)data;

View File

@ -5,6 +5,22 @@
Released under the CC0: https://creativecommons.org/publicdomain/zero/1.0/
*/
/* Use at the beginning of the coroutine, you must have declared a variable coro_t* coro */
#define CORO_ENTER() \
{ \
CORO_again: ; \
switch ( coro->step ) { \
case CORO_BEGIN: ;
/* Use to define labels which are targets to GOTO and GOSUB */
#define CORO_SUB( x ) \
case x: ;
/* Use at the end of the coroutine */
#define CORO_LEAVE() \
} } \
do { return 0; } while ( 0 )
/* Go to the x label */
#define CORO_GOTO( x ) \
do { \
@ -13,7 +29,6 @@ Released under the CC0: https://creativecommons.org/publicdomain/zero/1.0/
} while ( 0 )
/* Go to a subroutine, execution continues until the subroutine returns via RET */
/* x is the subroutine label, y and z are the A and B arguments */
#define CORO_GOSUB( x ) \
do { \
coro->stack[ coro->sp++ ] = __LINE__; \
@ -40,50 +55,16 @@ Released under the CC0: https://creativecommons.org/publicdomain/zero/1.0/
/* The coroutine entry point, never use 0 as a label */
#define CORO_BEGIN 0
/* Sets up a coroutine, x is a pointer to coro_t */
#define CORO_SETUP( x ) \
/* Sets up the coroutine */
#define CORO_SETUP() \
do { \
( x )->step = CORO_BEGIN; \
( x )->sp = 0; \
coro->step = CORO_BEGIN; \
coro->sp = 0; \
} while ( 0 )
/* A coroutine */
typedef struct
{
/* co-routine specific variables */
char badge_name[16];
char url[256];
char badge_basepath[PATH_MAX_LENGTH];
char badge_fullpath[PATH_MAX_LENGTH];
unsigned char hash[16];
bool round;
unsigned gameid;
unsigned i;
unsigned j;
unsigned k;
size_t bytes;
size_t count;
size_t offset;
size_t len;
size_t size;
MD5_CTX md5;
cheevos_nes_header_t header;
retro_time_t t0;
struct retro_system_info sysinfo;
void *data;
char *json;
const char *path;
const char *ext;
intfstream_t *stream;
cheevo_t *cheevo;
settings_t *settings;
struct http_connection_t *conn;
struct http_t *http;
const cheevo_t *cheevo_end;
/* co-routine general variables */
int step, sp;
/* Add this macro to your coro_t structure containing the variables for the coroutine */
#define CORO_FIELDS \
int step, sp; \
int stack[ 8 ];
} coro_t;
#endif /* CORO_H */