diff --git a/Makefile.common b/Makefile.common index 35a68e98c9..28e7cd1a4f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1710,76 +1710,72 @@ ifeq ($(HAVE_NETWORKING), 1) # RetroAchievements ifeq ($(HAVE_CHEEVOS), 1) - DEFINES += -DHAVE_CHEEVOS + DEFINES += -DHAVE_CHEEVOS \ + -Ideps/rcheevos/include - ifeq ($(HAVE_NEW_CHEEVOS), 1) - DEFINES += -DHAVE_NEW_CHEEVOS \ - -Ideps/rcheevos/include - OBJ += cheevos-new/cheevos.o \ - cheevos-new/badges.o \ - cheevos-new/fixup.o \ - cheevos-new/parser.o \ - cheevos-new/hash.o \ - deps/rcheevos/src/rcheevos/trigger.o \ - deps/rcheevos/src/rcheevos/condset.o \ - deps/rcheevos/src/rcheevos/condition.o \ - deps/rcheevos/src/rcheevos/operand.o \ - deps/rcheevos/src/rcheevos/term.o \ - deps/rcheevos/src/rcheevos/expression.o \ - deps/rcheevos/src/rcheevos/value.o \ - deps/rcheevos/src/rcheevos/lboard.o \ - deps/rcheevos/src/rcheevos/alloc.o \ - deps/rcheevos/src/rcheevos/format.o \ - deps/rcheevos/src/rurl/url.o + OBJ += cheevos/cheevos.o \ + cheevos/badges.o \ + cheevos/var.o \ + cheevos/cond.o \ + cheevos-new/cheevos.o \ + cheevos-new/fixup.o \ + cheevos-new/parser.o \ + cheevos-new/hash.o \ + deps/rcheevos/src/rcheevos/trigger.o \ + deps/rcheevos/src/rcheevos/condset.o \ + deps/rcheevos/src/rcheevos/condition.o \ + deps/rcheevos/src/rcheevos/operand.o \ + deps/rcheevos/src/rcheevos/term.o \ + deps/rcheevos/src/rcheevos/expression.o \ + deps/rcheevos/src/rcheevos/value.o \ + deps/rcheevos/src/rcheevos/lboard.o \ + deps/rcheevos/src/rcheevos/alloc.o \ + deps/rcheevos/src/rcheevos/format.o \ + deps/rcheevos/src/rcheevos/memref.o \ + deps/rcheevos/src/rcheevos/richpresence.o \ + deps/rcheevos/src/rurl/url.o - ifeq ($(HAVE_LUA), 1) - DEFINES += -DHAVE_LUA \ - -DLUA_32BITS \ - -Ideps/lua/src - OBJ += deps/lua/src/lapi.o \ - deps/lua/src/lcode.o \ - deps/lua/src/lctype.o \ - deps/lua/src/ldebug.o \ - deps/lua/src/ldo.o \ - deps/lua/src/ldump.o \ - deps/lua/src/lfunc.o \ - deps/lua/src/lgc.o \ - deps/lua/src/llex.o \ - deps/lua/src/lmem.o \ - deps/lua/src/lobject.o \ - deps/lua/src/lopcodes.o \ - deps/lua/src/lparser.o \ - deps/lua/src/lstate.o \ - deps/lua/src/lstring.o \ - deps/lua/src/ltable.o \ - deps/lua/src/ltm.o \ - deps/lua/src/lundump.o \ - deps/lua/src/lvm.o \ - deps/lua/src/lzio.o \ - deps/lua/src/lauxlib.o \ - deps/lua/src/lbaselib.o \ - deps/lua/src/lbitlib.o \ - deps/lua/src/lcorolib.o \ - deps/lua/src/ldblib.o \ - deps/lua/src/liolib.o \ - deps/lua/src/lmathlib.o \ - deps/lua/src/loslib.o \ - deps/lua/src/lstrlib.o \ - deps/lua/src/ltablib.o \ - deps/lua/src/lutf8lib.o \ - deps/lua/src/loadlib.o \ - deps/lua/src/linit.o - else - DEFINES += -DRC_DISABLE_LUA - endif - - # if not HAVE_NEW_CHEEVOS + ifeq ($(HAVE_LUA), 1) + DEFINES += -DHAVE_LUA \ + -DLUA_32BITS \ + -Ideps/lua/src + OBJ += deps/lua/src/lapi.o \ + deps/lua/src/lcode.o \ + deps/lua/src/lctype.o \ + deps/lua/src/ldebug.o \ + deps/lua/src/ldo.o \ + deps/lua/src/ldump.o \ + deps/lua/src/lfunc.o \ + deps/lua/src/lgc.o \ + deps/lua/src/llex.o \ + deps/lua/src/lmem.o \ + deps/lua/src/lobject.o \ + deps/lua/src/lopcodes.o \ + deps/lua/src/lparser.o \ + deps/lua/src/lstate.o \ + deps/lua/src/lstring.o \ + deps/lua/src/ltable.o \ + deps/lua/src/ltm.o \ + deps/lua/src/lundump.o \ + deps/lua/src/lvm.o \ + deps/lua/src/lzio.o \ + deps/lua/src/lauxlib.o \ + deps/lua/src/lbaselib.o \ + deps/lua/src/lbitlib.o \ + deps/lua/src/lcorolib.o \ + deps/lua/src/ldblib.o \ + deps/lua/src/liolib.o \ + deps/lua/src/lmathlib.o \ + deps/lua/src/loslib.o \ + deps/lua/src/lstrlib.o \ + deps/lua/src/ltablib.o \ + deps/lua/src/lutf8lib.o \ + deps/lua/src/loadlib.o \ + deps/lua/src/linit.o else - OBJ += cheevos/cheevos.o \ - cheevos/badges.o \ - cheevos/var.o \ - cheevos/cond.o + DEFINES += -DRC_DISABLE_LUA endif + endif ifeq ($(HAVE_DISCORD), 1) diff --git a/cheevos-new/cheevos.c b/cheevos-new/cheevos.c index 0a0d7ba6ac..c9822cb93a 100644 --- a/cheevos-new/cheevos.c +++ b/cheevos-new/cheevos.c @@ -44,7 +44,7 @@ #include #endif -#include "badges.h" +#include "../cheevos/badges.h" /* RCHEEVOS TODO: fix path */ #include "cheevos.h" #include "fixup.h" #include "parser.h" @@ -97,19 +97,19 @@ typedef struct { rc_trigger_t* trigger; - const cheevos_racheevo_t* info; + const rcheevos_racheevo_t* info; int active; int last; -} cheevos_cheevo_t; +} rcheevos_cheevo_t; typedef struct { rc_lboard_t* lboard; - const cheevos_ralboard_t* info; + const rcheevos_ralboard_t* info; bool active; unsigned last_value; int format; -} cheevos_lboard_t; +} rcheevos_lboard_t; typedef struct { @@ -120,22 +120,22 @@ typedef struct bool core_supports; - cheevos_rapatchdata_t patchdata; - cheevos_cheevo_t* core; - cheevos_cheevo_t* unofficial; - cheevos_lboard_t* lboards; + rcheevos_rapatchdata_t patchdata; + rcheevos_cheevo_t* core; + rcheevos_cheevo_t* unofficial; + rcheevos_lboard_t* lboards; - cheevos_fixups_t fixups; + rcheevos_fixups_t fixups; char token[32]; -} cheevos_locals_t; +} rcheevos_locals_t; typedef struct { int label; const char* name; const uint32_t* ext_hashes; -} cheevos_finder_t; +} rcheevos_finder_t; typedef struct { @@ -145,9 +145,9 @@ typedef struct uint8_t rom_type; uint8_t rom_type2; uint8_t reserve[8]; -} cheevos_nes_header_t; +} rcheevos_nes_header_t; -static cheevos_locals_t cheevos_locals = +static rcheevos_locals_t rcheevos_locals = { NULL, /* task */ #ifdef HAVE_THREADS @@ -162,12 +162,12 @@ static cheevos_locals_t cheevos_locals = {0}, /* token */ }; -bool cheevos_loaded = false; -bool cheevos_hardcore_active = false; -bool cheevos_hardcore_paused = false; -bool cheevos_state_loaded_flag = false; -int cheats_are_enabled = 0; -int cheats_were_enabled = 0; +bool rcheevos_loaded = false; +bool rcheevos_hardcore_active = false; +bool rcheevos_hardcore_paused = false; +bool rcheevos_state_loaded_flag = false; +int rcheevos_cheats_are_enabled = 0; +int rcheevos_cheats_were_enabled = 0; #ifdef HAVE_THREADS #define CHEEVOS_LOCK(l) do { slock_lock(l); } while (0) @@ -185,14 +185,14 @@ Supporting functions. #ifndef CHEEVOS_VERBOSE -void cheevos_log(const char *fmt, ...) +void rcheevos_log(const char *fmt, ...) { (void)fmt; } #endif -static void cheevos_log_url(const char* format, const char* url) +static void rcheevos_log_url(const char* format, const char* url) { #ifdef CHEEVOS_LOG_URLS #ifdef CHEEVOS_LOG_PASSWORD @@ -255,7 +255,7 @@ static void cheevos_log_url(const char* format, const char* url) #endif } -static const char* cheevos_rc_error(int ret) +static const char* rcheevos_rc_error(int ret) { switch (ret) { @@ -281,52 +281,52 @@ static const char* cheevos_rc_error(int ret) } } -static int cheevos_parse(const char* json) +static int rcheevos_parse(const char* json) { int res = 0; int i = 0; unsigned j = 0; unsigned count = 0; - cheevos_cheevo_t* cheevo = NULL; - cheevos_lboard_t* lboard = NULL; - cheevos_racheevo_t* rac = NULL; + rcheevos_cheevo_t* cheevo = NULL; + rcheevos_lboard_t* lboard = NULL; + rcheevos_racheevo_t* rac = NULL; - cheevos_fixup_init(&cheevos_locals.fixups); + rcheevos_fixup_init(&rcheevos_locals.fixups); - res = cheevos_get_patchdata(json, &cheevos_locals.patchdata); + res = rcheevos_get_patchdata(json, &rcheevos_locals.patchdata); if (res != 0) { - RARCH_ERR(CHEEVOS_TAG "Error parsing cheevos"); + RARCH_ERR(RCHEEVOS_TAG "Error parsing cheevos"); return -1; } - if ( cheevos_locals.patchdata.core_count == 0 - && !cheevos_locals.patchdata.unofficial_count == 0 - && !cheevos_locals.patchdata.lboard_count == 0) + if ( rcheevos_locals.patchdata.core_count == 0 + && rcheevos_locals.patchdata.unofficial_count == 0 + && rcheevos_locals.patchdata.lboard_count == 0) { - cheevos_locals.core = NULL; - cheevos_locals.unofficial = NULL; - cheevos_locals.lboards = NULL; - cheevos_free_patchdata(&cheevos_locals.patchdata); + rcheevos_locals.core = NULL; + rcheevos_locals.unofficial = NULL; + rcheevos_locals.lboards = NULL; + rcheevos_free_patchdata(&rcheevos_locals.patchdata); return 0; } /* Allocate memory. */ - cheevos_locals.core = (cheevos_cheevo_t*) - calloc(cheevos_locals.patchdata.core_count, sizeof(cheevos_cheevo_t)); + rcheevos_locals.core = (rcheevos_cheevo_t*) + calloc(rcheevos_locals.patchdata.core_count, sizeof(rcheevos_cheevo_t)); - cheevos_locals.unofficial = (cheevos_cheevo_t*) - calloc(cheevos_locals.patchdata.unofficial_count, sizeof(cheevos_cheevo_t)); + rcheevos_locals.unofficial = (rcheevos_cheevo_t*) + calloc(rcheevos_locals.patchdata.unofficial_count, sizeof(rcheevos_cheevo_t)); - cheevos_locals.lboards = (cheevos_lboard_t*) - calloc(cheevos_locals.patchdata.lboard_count, sizeof(cheevos_lboard_t)); + rcheevos_locals.lboards = (rcheevos_lboard_t*) + calloc(rcheevos_locals.patchdata.lboard_count, sizeof(rcheevos_lboard_t)); - if ( !cheevos_locals.core - || !cheevos_locals.unofficial - || !cheevos_locals.lboards) + if ( !rcheevos_locals.core + || !rcheevos_locals.unofficial + || !rcheevos_locals.lboards) { - CHEEVOS_ERR(CHEEVOS_TAG "Error allocating memory for cheevos"); + CHEEVOS_ERR(RCHEEVOS_TAG "Error allocating memory for cheevos"); goto error; } @@ -335,15 +335,15 @@ static int cheevos_parse(const char* json) { if (i == 0) { - cheevo = cheevos_locals.core; - rac = cheevos_locals.patchdata.core; - count = cheevos_locals.patchdata.core_count; + cheevo = rcheevos_locals.core; + rac = rcheevos_locals.patchdata.core; + count = rcheevos_locals.patchdata.core_count; } else { - cheevo = cheevos_locals.unofficial; - rac = cheevos_locals.patchdata.unofficial; - count = cheevos_locals.patchdata.unofficial_count; + cheevo = rcheevos_locals.unofficial; + rac = rcheevos_locals.patchdata.unofficial; + count = rcheevos_locals.patchdata.unofficial_count; } for (j = 0; j < count; j++, cheevo++, rac++) @@ -353,8 +353,8 @@ static int cheevos_parse(const char* json) if (res < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Error in cheevo memaddr %s: %s", - cheevo->info->memaddr, cheevos_rc_error(res)); + CHEEVOS_ERR(RCHEEVOS_TAG "Error in cheevo memaddr %s: %s", + cheevo->info->memaddr, rcheevos_rc_error(res)); goto error; } @@ -362,28 +362,28 @@ static int cheevos_parse(const char* json) if (!cheevo->trigger) { - CHEEVOS_ERR(CHEEVOS_TAG "Error allocating memory for cheevos"); + CHEEVOS_ERR(RCHEEVOS_TAG "Error allocating memory for cheevos"); goto error; } rc_parse_trigger(cheevo->trigger, cheevo->info->memaddr, NULL, 0); - cheevo->active = CHEEVOS_ACTIVE_SOFTCORE | CHEEVOS_ACTIVE_HARDCORE; + cheevo->active = RCHEEVOS_ACTIVE_SOFTCORE | RCHEEVOS_ACTIVE_HARDCORE; cheevo->last = 1; } } - lboard = cheevos_locals.lboards; - count = cheevos_locals.patchdata.lboard_count; + lboard = rcheevos_locals.lboards; + count = rcheevos_locals.patchdata.lboard_count; for (j = 0; j < count; j++, lboard++) { - lboard->info = cheevos_locals.patchdata.lboards + j; + lboard->info = rcheevos_locals.patchdata.lboards + j; res = rc_lboard_size(lboard->info->mem); if (res < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Error in leaderboard mem %s: %s", - lboard->info->mem, cheevos_rc_error(res)); + CHEEVOS_ERR(RCHEEVOS_TAG "Error in leaderboard mem %s: %s", + lboard->info->mem, rcheevos_rc_error(res)); goto error; } @@ -391,7 +391,7 @@ static int cheevos_parse(const char* json) if (!lboard->lboard) { - CHEEVOS_ERR(CHEEVOS_TAG "Error allocating memory for cheevos"); + CHEEVOS_ERR(RCHEEVOS_TAG "Error allocating memory for cheevos"); goto error; } @@ -405,11 +405,11 @@ static int cheevos_parse(const char* json) return 0; error: - CHEEVOS_FREE(cheevos_locals.core); - CHEEVOS_FREE(cheevos_locals.unofficial); - CHEEVOS_FREE(cheevos_locals.lboards); - cheevos_free_patchdata(&cheevos_locals.patchdata); - cheevos_fixup_destroy(&cheevos_locals.fixups); + CHEEVOS_FREE(rcheevos_locals.core); + CHEEVOS_FREE(rcheevos_locals.unofficial); + CHEEVOS_FREE(rcheevos_locals.lboards); + rcheevos_free_patchdata(&rcheevos_locals.patchdata); + rcheevos_fixup_destroy(&rcheevos_locals.fixups); return -1; } @@ -417,82 +417,82 @@ error: Test all the achievements (call once per frame). *****************************************************************************/ -static void cheevos_award_task_softcore(retro_task_t *task, void* task_data, void* user_data, +static void rcheevos_award_task_softcore(retro_task_t *task, void* task_data, void* user_data, const char* error) { settings_t *settings = config_get_ptr(); - const cheevos_cheevo_t* cheevo = (const cheevos_cheevo_t*)user_data; + const rcheevos_cheevo_t* cheevo = (const rcheevos_cheevo_t*)user_data; char buffer[256]; int ret; buffer[0] = 0; if (error == NULL) { - CHEEVOS_LOG(CHEEVOS_TAG "Awarded achievement %u\n", cheevo->info->id); + CHEEVOS_LOG(RCHEEVOS_TAG "Awarded achievement %u\n", cheevo->info->id); return; } if (*error) - CHEEVOS_ERR(CHEEVOS_TAG "Error awarding achievement %u: %s\n", cheevo->info->id, error); + CHEEVOS_ERR(RCHEEVOS_TAG "Error awarding achievement %u: %s\n", cheevo->info->id, error); /* Try again. */ - ret = rc_url_award_cheevo(buffer, sizeof(buffer), settings->arrays.cheevos_username, cheevos_locals.token, cheevo->info->id, 0); + ret = rc_url_award_cheevo(buffer, sizeof(buffer), settings->arrays.cheevos_username, rcheevos_locals.token, cheevo->info->id, 0); if (ret != 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Buffer to small to create URL"); + CHEEVOS_ERR(RCHEEVOS_TAG "Buffer to small to create URL"); return; } - cheevos_log_url(CHEEVOS_TAG "rc_url_award_cheevo: %s\n", buffer); - task_push_http_transfer(buffer, true, NULL, cheevos_award_task_softcore, user_data); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_award_cheevo: %s\n", buffer); + task_push_http_transfer(buffer, true, NULL, rcheevos_award_task_softcore, user_data); } -static void cheevos_award_task_hardcore(retro_task_t *task, void* task_data, void* user_data, +static void rcheevos_award_task_hardcore(retro_task_t *task, void* task_data, void* user_data, const char* error) { settings_t *settings = config_get_ptr(); - const cheevos_cheevo_t* cheevo = (const cheevos_cheevo_t*)user_data; + const rcheevos_cheevo_t* cheevo = (const rcheevos_cheevo_t*)user_data; char buffer[256]; int ret; buffer[0] = 0; if (error == NULL) { - CHEEVOS_LOG(CHEEVOS_TAG "Awarded achievement %u\n", cheevo->info->id); + CHEEVOS_LOG(RCHEEVOS_TAG "Awarded achievement %u\n", cheevo->info->id); return; } if (*error) - CHEEVOS_ERR(CHEEVOS_TAG "Error awarding achievement %u: %s\n", cheevo->info->id, error); + CHEEVOS_ERR(RCHEEVOS_TAG "Error awarding achievement %u: %s\n", cheevo->info->id, error); /* Try again. */ - ret = rc_url_award_cheevo(buffer, sizeof(buffer), settings->arrays.cheevos_username, cheevos_locals.token, cheevo->info->id, 1); + ret = rc_url_award_cheevo(buffer, sizeof(buffer), settings->arrays.cheevos_username, rcheevos_locals.token, cheevo->info->id, 1); if (ret != 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Buffer to small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "Buffer to small to create URL\n"); return; } - cheevos_log_url(CHEEVOS_TAG "rc_url_award_cheevo: %s\n", buffer); - task_push_http_transfer(buffer, true, NULL, cheevos_award_task_hardcore, user_data); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_award_cheevo: %s\n", buffer); + task_push_http_transfer(buffer, true, NULL, rcheevos_award_task_hardcore, user_data); } -static void cheevos_award(cheevos_cheevo_t* cheevo, int mode) +static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode) { settings_t *settings = config_get_ptr(); char buffer[256]; buffer[0] = 0; - CHEEVOS_LOG(CHEEVOS_TAG "awarding cheevo %u: %s (%s)\n", + CHEEVOS_LOG(RCHEEVOS_TAG "awarding cheevo %u: %s (%s)\n", cheevo->info->id, cheevo->info->title, cheevo->info->description); /* Deactivates the cheevo. */ cheevo->active &= ~mode; - if (mode == CHEEVOS_ACTIVE_HARDCORE) - cheevo->active &= ~CHEEVOS_ACTIVE_SOFTCORE; + if (mode == RCHEEVOS_ACTIVE_HARDCORE) + cheevo->active &= ~RCHEEVOS_ACTIVE_SOFTCORE; /* Show the OSD message. */ #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) @@ -505,10 +505,10 @@ static void cheevos_award(cheevos_cheevo_t* cheevo, int mode) } /* Start the award task. */ - if ((mode & CHEEVOS_ACTIVE_HARDCORE) != 0) - cheevos_award_task_hardcore(NULL, NULL, cheevo, ""); + if ((mode & RCHEEVOS_ACTIVE_HARDCORE) != 0) + rcheevos_award_task_hardcore(NULL, NULL, cheevo, ""); else - cheevos_award_task_softcore(NULL, NULL, cheevo, ""); + rcheevos_award_task_softcore(NULL, NULL, cheevo, ""); /* Take a screenshot of the achievement. */ if (settings && settings->bools.cheevos_auto_screenshot) @@ -523,16 +523,16 @@ static void cheevos_award(cheevos_cheevo_t* cheevo, int mode) if (take_screenshot(shotname, true, video_driver_cached_frame_has_valid_framebuffer(), false, true)) - CHEEVOS_LOG(CHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id); + CHEEVOS_LOG(RCHEEVOS_TAG "got a screenshot for cheevo %u\n", cheevo->info->id); else - CHEEVOS_LOG(CHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id); + CHEEVOS_LOG(RCHEEVOS_TAG "failed to get screenshot for cheevo %u\n", cheevo->info->id); } } -static unsigned cheevos_peek(unsigned address, unsigned num_bytes, void* ud) +static unsigned rcheevos_peek(unsigned address, unsigned num_bytes, void* ud) { - const uint8_t* data = cheevos_fixup_find(&cheevos_locals.fixups, - address, cheevos_locals.patchdata.console_id); + const uint8_t* data = rcheevos_fixup_find(&rcheevos_locals.fixups, + address, rcheevos_locals.patchdata.console_id); unsigned value = 0; if (data) @@ -548,25 +548,25 @@ static unsigned cheevos_peek(unsigned address, unsigned num_bytes, void* ud) return value; } -static void cheevos_test_cheevo_set(bool official) +static void rcheevos_test_cheevo_set(bool official) { settings_t *settings = config_get_ptr(); - int mode = CHEEVOS_ACTIVE_SOFTCORE; - cheevos_cheevo_t* cheevo; + int mode = RCHEEVOS_ACTIVE_SOFTCORE; + rcheevos_cheevo_t* cheevo; int i, count; - if (settings && settings->bools.cheevos_hardcore_mode_enable && !cheevos_hardcore_paused) - mode = CHEEVOS_ACTIVE_HARDCORE; + if (settings && settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused) + mode = RCHEEVOS_ACTIVE_HARDCORE; if (official) { - cheevo = cheevos_locals.core; - count = cheevos_locals.patchdata.core_count; + cheevo = rcheevos_locals.core; + count = rcheevos_locals.patchdata.core_count; } else { - cheevo = cheevos_locals.unofficial; - count = cheevos_locals.patchdata.unofficial_count; + cheevo = rcheevos_locals.unofficial; + count = rcheevos_locals.patchdata.unofficial_count; } for (i = 0; i < count; i++, cheevo++) @@ -577,23 +577,23 @@ static void cheevos_test_cheevo_set(bool official) if (cheevo->active & mode) { - int valid = rc_test_trigger(cheevo->trigger, cheevos_peek, NULL, NULL); + int valid = rc_test_trigger(cheevo->trigger, rcheevos_peek, NULL, NULL); if (cheevo->last) rc_reset_trigger(cheevo->trigger); else if (valid) - cheevos_award(cheevo, mode); + rcheevos_award(cheevo, mode); cheevo->last = valid; } } } -static void cheevos_lboard_submit_task(retro_task_t *task, void* task_data, void* user_data, +static void rcheevos_lboard_submit_task(retro_task_t *task, void* task_data, void* user_data, const char* error) { settings_t *settings = config_get_ptr(); - const cheevos_lboard_t* lboard = (const cheevos_lboard_t*)user_data; + const rcheevos_lboard_t* lboard = (const rcheevos_lboard_t*)user_data; MD5_CTX ctx; uint8_t hash[16]; char signature[64]; @@ -602,11 +602,11 @@ static void cheevos_lboard_submit_task(retro_task_t *task, void* task_data, void if (!error) { - CHEEVOS_LOG(CHEEVOS_TAG "Submitted leaderboard %u\n", lboard->info->id); + CHEEVOS_LOG(RCHEEVOS_TAG "Submitted leaderboard %u\n", lboard->info->id); return; } - CHEEVOS_ERR(CHEEVOS_TAG "Error submitting leaderboard %u: %s\n", lboard->info->id, error); + CHEEVOS_ERR(RCHEEVOS_TAG "Error submitting leaderboard %u: %s\n", lboard->info->id, error); /* Try again. */ @@ -620,19 +620,19 @@ static void cheevos_lboard_submit_task(retro_task_t *task, void* task_data, void MD5_Final(hash, &ctx); /* Start the request. */ - ret = rc_url_submit_lboard(buffer, sizeof(buffer), settings->arrays.cheevos_username, cheevos_locals.token, lboard->info->id, lboard->last_value, hash); + ret = rc_url_submit_lboard(buffer, sizeof(buffer), settings->arrays.cheevos_username, rcheevos_locals.token, lboard->info->id, lboard->last_value, hash); if (ret != 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Buffer to small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "Buffer to small to create URL\n"); return; } - cheevos_log_url(CHEEVOS_TAG "rc_url_submit_lboard: %s\n", buffer); - task_push_http_transfer(buffer, true, NULL, cheevos_lboard_submit_task, user_data); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_submit_lboard: %s\n", buffer); + task_push_http_transfer(buffer, true, NULL, rcheevos_lboard_submit_task, user_data); } -static void cheevos_lboard_submit(cheevos_lboard_t* lboard) +static void rcheevos_lboard_submit(rcheevos_lboard_t* lboard) { char buffer[256]; char value[16]; @@ -643,7 +643,7 @@ static void cheevos_lboard_submit(cheevos_lboard_t* lboard) /* Failsafe for improper leaderboards. */ if (lboard->last_value == 0) { - CHEEVOS_ERR(CHEEVOS_TAG "Leaderboard %s tried to submit 0\n", lboard->info->title); + CHEEVOS_ERR(RCHEEVOS_TAG "Leaderboard %s tried to submit 0\n", lboard->info->title); runloop_msg_queue_push("Leaderboard attempt cancelled!", 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); return; } @@ -656,45 +656,44 @@ static void cheevos_lboard_submit(cheevos_lboard_t* lboard) runloop_msg_queue_push(buffer, 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); /* Start the submit task. */ - cheevos_lboard_submit_task(NULL, NULL, lboard, "no error, first try"); + rcheevos_lboard_submit_task(NULL, NULL, lboard, "no error, first try"); } -static void cheevos_test_leaderboards(void) +static void rcheevos_test_leaderboards(void) { - cheevos_lboard_t* lboard = cheevos_locals.lboards; + rcheevos_lboard_t* lboard = rcheevos_locals.lboards; unsigned i; - unsigned value; - for (i = 0; i < cheevos_locals.patchdata.lboard_count; i++, lboard++) + for (i = 0; i < rcheevos_locals.patchdata.lboard_count; i++, lboard++) { - if (lboard->active) + switch (rc_evaluate_lboard(lboard->lboard, &lboard->last_value, rcheevos_peek, NULL, NULL)) { - value = rc_evaluate_value(&lboard->lboard->value, cheevos_peek, NULL, NULL); + default: + case RC_LBOARD_INACTIVE: + break; - if (value != lboard->last_value) + case RC_LBOARD_ACTIVE: + // this is where we would update the onscreen tracker + break; + + case RC_LBOARD_TRIGGERED: + rcheevos_lboard_submit(lboard); + break; + + case RC_LBOARD_CANCELED: { - CHEEVOS_LOG(CHEEVOS_TAG "Value lboard %s %u\n", lboard->info->title, value); - lboard->last_value = value; - } - - if (rc_test_trigger(&lboard->lboard->submit, cheevos_peek, NULL, NULL)) - cheevos_lboard_submit(lboard); - - if (rc_test_trigger(&lboard->lboard->cancel, cheevos_peek, NULL, NULL)) - { - CHEEVOS_LOG(CHEEVOS_TAG "Cancel leaderboard %s\n", lboard->info->title); + CHEEVOS_LOG(RCHEEVOS_TAG "Cancel leaderboard %s\n", lboard->info->title); lboard->active = 0; runloop_msg_queue_push("Leaderboard attempt cancelled!", 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + break; } - } - else - { - if (rc_test_trigger(&lboard->lboard->start, cheevos_peek, NULL, NULL)) + + case RC_LBOARD_STARTED: { char buffer[256]; - CHEEVOS_LOG(CHEEVOS_TAG "Leaderboard started: %s\n", lboard->info->title); + CHEEVOS_LOG(RCHEEVOS_TAG "Leaderboard started: %s\n", lboard->info->title); lboard->active = 1; lboard->last_value = 0; @@ -702,50 +701,51 @@ static void cheevos_test_leaderboards(void) "Leaderboard Active: %s", lboard->info->title); runloop_msg_queue_push(buffer, 0, 2 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); runloop_msg_queue_push(lboard->info->description, 0, 3 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + break; } } } } -void cheevos_reset_game(void) +void rcheevos_reset_game(void) { - cheevos_cheevo_t* cheevo; - cheevos_lboard_t* lboard; + rcheevos_cheevo_t* cheevo; + rcheevos_lboard_t* lboard; unsigned i; - cheevo = cheevos_locals.core; - for (i = 0; i < cheevos_locals.patchdata.core_count; i++, cheevo++) + cheevo = rcheevos_locals.core; + for (i = 0; i < rcheevos_locals.patchdata.core_count; i++, cheevo++) { cheevo->last = 1; } - cheevo = cheevos_locals.unofficial; - for (i = 0; i < cheevos_locals.patchdata.unofficial_count; i++, cheevo++) + cheevo = rcheevos_locals.unofficial; + for (i = 0; i < rcheevos_locals.patchdata.unofficial_count; i++, cheevo++) { cheevo->last = 1; } - lboard = cheevos_locals.lboards; - for (i = 0; i < cheevos_locals.patchdata.lboard_count; i++, lboard++) + lboard = rcheevos_locals.lboards; + for (i = 0; i < rcheevos_locals.patchdata.lboard_count; i++, lboard++) { lboard->active = 0; } } -void cheevos_populate_menu(void* data) +void rcheevos_populate_menu(void* data) { #ifdef HAVE_MENU int i = 0; int count = 0; settings_t* settings = config_get_ptr(); menu_displaylist_info_t* info = (menu_displaylist_info_t*)data; - cheevos_cheevo_t* cheevo = NULL; + rcheevos_cheevo_t* cheevo = NULL; if ( settings->bools.cheevos_enable && settings->bools.cheevos_hardcore_mode_enable - && cheevos_loaded) + && rcheevos_loaded) { - if (!cheevos_hardcore_paused) + if (!rcheevos_hardcore_paused) menu_entries_append_enum(info->list, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACHIEVEMENT_PAUSE), msg_hash_to_str(MENU_ENUM_LABEL_ACHIEVEMENT_PAUSE), @@ -759,11 +759,11 @@ void cheevos_populate_menu(void* data) MENU_SETTING_ACTION_RESUME_ACHIEVEMENTS, 0, 0); } - cheevo = cheevos_locals.core; + cheevo = rcheevos_locals.core; - for (i = 0, count = cheevos_locals.patchdata.core_count; i < count; i++, cheevo++) + for (i = 0, count = rcheevos_locals.patchdata.core_count; i < count; i++, cheevo++) { - if (!(cheevo->active & CHEEVOS_ACTIVE_HARDCORE)) + if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE)) { menu_entries_append_enum(info->list, cheevo->info->title, cheevo->info->description, @@ -771,9 +771,9 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_HARDCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_HARDCORE)); } - else if (!(cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)) + else if (!(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)) { menu_entries_append_enum(info->list, cheevo->info->title, cheevo->info->description, @@ -781,7 +781,7 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)); } else { @@ -791,17 +791,17 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)); } } if (settings->bools.cheevos_test_unofficial) { - cheevo = cheevos_locals.unofficial; + cheevo = rcheevos_locals.unofficial; - for (i = 0, count = cheevos_locals.patchdata.unofficial_count; i < count; i++, cheevo++) + for (i = 0, count = rcheevos_locals.patchdata.unofficial_count; i < count; i++, cheevo++) { - if (!(cheevo->active & CHEEVOS_ACTIVE_HARDCORE)) + if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE)) { menu_entries_append_enum(info->list, cheevo->info->title, cheevo->info->description, @@ -809,9 +809,9 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_HARDCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_HARDCORE)); } - else if (!(cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)) + else if (!(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)) { menu_entries_append_enum(info->list, cheevo->info->title, cheevo->info->description, @@ -819,7 +819,7 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)); } else { @@ -829,15 +829,15 @@ void cheevos_populate_menu(void* data) MENU_SETTINGS_CHEEVOS_START + i, 0, 0); set_badge_info(&badges_ctx, i, cheevo->info->badge, - (cheevo->active & CHEEVOS_ACTIVE_SOFTCORE)); + (cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)); } } } - count = cheevos_locals.patchdata.core_count; + count = rcheevos_locals.patchdata.core_count; if (settings->bools.cheevos_test_unofficial) - count += cheevos_locals.patchdata.unofficial_count; + count += rcheevos_locals.patchdata.unofficial_count; if (count == 0) { @@ -850,28 +850,28 @@ void cheevos_populate_menu(void* data) #endif } -bool cheevos_get_description(cheevos_ctx_desc_t* desc) +bool rcheevos_get_description(rcheevos_ctx_desc_t* desc) { unsigned idx; - const cheevos_cheevo_t* cheevo; + const rcheevos_cheevo_t* cheevo; if (!desc) return false; *desc->s = 0; - if (cheevos_loaded) + if (rcheevos_loaded) { idx = desc->idx; - if (idx < cheevos_locals.patchdata.core_count) - cheevo = cheevos_locals.core + idx; + if (idx < rcheevos_locals.patchdata.core_count) + cheevo = rcheevos_locals.core + idx; else { - idx -= cheevos_locals.patchdata.core_count; + idx -= rcheevos_locals.patchdata.core_count; - if (idx < cheevos_locals.patchdata.unofficial_count) - cheevo = cheevos_locals.unofficial + idx; + if (idx < rcheevos_locals.patchdata.unofficial_count) + cheevo = rcheevos_locals.unofficial + idx; else return true; } @@ -882,74 +882,74 @@ bool cheevos_get_description(cheevos_ctx_desc_t* desc) return true; } -bool cheevos_apply_cheats(bool* data_bool) +bool rcheevos_apply_cheats(bool* data_bool) { - cheats_are_enabled = *data_bool; - cheats_were_enabled |= cheats_are_enabled; + rcheevos_cheats_are_enabled = *data_bool; + rcheevos_cheats_were_enabled |= rcheevos_cheats_are_enabled; return true; } -bool cheevos_unload(void) +bool rcheevos_unload(void) { bool running = false; unsigned i = 0, count = 0; - CHEEVOS_LOCK(cheevos_locals.task_lock); - running = cheevos_locals.task != NULL; - CHEEVOS_UNLOCK(cheevos_locals.task_lock); + CHEEVOS_LOCK(rcheevos_locals.task_lock); + running = rcheevos_locals.task != NULL; + CHEEVOS_UNLOCK(rcheevos_locals.task_lock); if (running) { - CHEEVOS_LOG(CHEEVOS_TAG "Asked the load thread to terminate\n"); - task_queue_cancel_task(cheevos_locals.task); + CHEEVOS_LOG(RCHEEVOS_TAG "Asked the load thread to terminate\n"); + task_queue_cancel_task(rcheevos_locals.task); #ifdef HAVE_THREADS do { - CHEEVOS_LOCK(cheevos_locals.task_lock); - running = cheevos_locals.task != NULL; - CHEEVOS_UNLOCK(cheevos_locals.task_lock); + CHEEVOS_LOCK(rcheevos_locals.task_lock); + running = rcheevos_locals.task != NULL; + CHEEVOS_UNLOCK(rcheevos_locals.task_lock); } while (running); #endif } - if (cheevos_loaded) + if (rcheevos_loaded) { - for (i = 0, count = cheevos_locals.patchdata.core_count; i < count; i++) + for (i = 0, count = rcheevos_locals.patchdata.core_count; i < count; i++) { - CHEEVOS_FREE(cheevos_locals.core[i].trigger); + CHEEVOS_FREE(rcheevos_locals.core[i].trigger); } - for (i = 0, count = cheevos_locals.patchdata.unofficial_count; i < count; i++) + for (i = 0, count = rcheevos_locals.patchdata.unofficial_count; i < count; i++) { - CHEEVOS_FREE(cheevos_locals.unofficial[i].trigger); + CHEEVOS_FREE(rcheevos_locals.unofficial[i].trigger); } - for (i = 0, count = cheevos_locals.patchdata.lboard_count; i < count; i++) + for (i = 0, count = rcheevos_locals.patchdata.lboard_count; i < count; i++) { - CHEEVOS_FREE(cheevos_locals.lboards[i].lboard); + CHEEVOS_FREE(rcheevos_locals.lboards[i].lboard); } - CHEEVOS_FREE(cheevos_locals.core); - CHEEVOS_FREE(cheevos_locals.unofficial); - CHEEVOS_FREE(cheevos_locals.lboards); - cheevos_free_patchdata(&cheevos_locals.patchdata); - cheevos_fixup_destroy(&cheevos_locals.fixups); + CHEEVOS_FREE(rcheevos_locals.core); + CHEEVOS_FREE(rcheevos_locals.unofficial); + CHEEVOS_FREE(rcheevos_locals.lboards); + rcheevos_free_patchdata(&rcheevos_locals.patchdata); + rcheevos_fixup_destroy(&rcheevos_locals.fixups); - cheevos_locals.core = NULL; - cheevos_locals.unofficial = NULL; - cheevos_locals.lboards = NULL; + rcheevos_locals.core = NULL; + rcheevos_locals.unofficial = NULL; + rcheevos_locals.lboards = NULL; - cheevos_loaded = false; - cheevos_hardcore_paused = false; + rcheevos_loaded = false; + rcheevos_hardcore_paused = false; } return true; } -bool cheevos_toggle_hardcore_mode(void) +bool rcheevos_toggle_hardcore_mode(void) { settings_t *settings = config_get_ptr(); @@ -958,13 +958,13 @@ bool cheevos_toggle_hardcore_mode(void) /* reset and deinit rewind to avoid cheat the score */ if ( settings->bools.cheevos_hardcore_mode_enable - && !cheevos_hardcore_paused) + && !rcheevos_hardcore_paused) { const char *msg = msg_hash_to_str( MSG_CHEEVOS_HARDCORE_MODE_ENABLE); /* reset the state loaded flag in case it was set */ - cheevos_state_loaded_flag = false; + rcheevos_state_loaded_flag = false; /* send reset core cmd to avoid any user * savestate previusly loaded. */ @@ -985,48 +985,48 @@ bool cheevos_toggle_hardcore_mode(void) return true; } -void cheevos_test(void) +void rcheevos_test(void) { settings_t *settings = config_get_ptr(); - cheevos_test_cheevo_set(true); + rcheevos_test_cheevo_set(true); if (settings) { if (settings->bools.cheevos_test_unofficial) - cheevos_test_cheevo_set(false); + rcheevos_test_cheevo_set(false); if (settings->bools.cheevos_hardcore_mode_enable && settings->bools.cheevos_leaderboards_enable && - !cheevos_hardcore_paused) - cheevos_test_leaderboards(); + !rcheevos_hardcore_paused) + rcheevos_test_leaderboards(); } } -bool cheevos_set_cheats(void) +bool rcheevos_set_cheats(void) { - cheats_were_enabled = cheats_are_enabled; + rcheevos_cheats_were_enabled = rcheevos_cheats_are_enabled; return true; } -void cheevos_set_support_cheevos(bool state) +void rcheevos_set_support_cheevos(bool state) { - cheevos_locals.core_supports = state; + rcheevos_locals.core_supports = state; } -bool cheevos_get_support_cheevos(void) +bool rcheevos_get_support_cheevos(void) { - return cheevos_locals.core_supports; + return rcheevos_locals.core_supports; } -int cheevos_get_console(void) +int rcheevos_get_console(void) { - return cheevos_locals.patchdata.console_id; + return rcheevos_locals.patchdata.console_id; } -static void cheevos_unlock_cb(unsigned id, void* userdata) +static void rcheevos_unlock_cb(unsigned id, void* userdata) { - cheevos_cheevo_t* cheevo = NULL; + rcheevos_cheevo_t* cheevo = NULL; int i = 0; unsigned j = 0, count = 0; @@ -1034,13 +1034,13 @@ static void cheevos_unlock_cb(unsigned id, void* userdata) { if (i == 0) { - cheevo = cheevos_locals.core; - count = cheevos_locals.patchdata.core_count; + cheevo = rcheevos_locals.core; + count = rcheevos_locals.patchdata.core_count; } else { - cheevo = cheevos_locals.unofficial; - count = cheevos_locals.patchdata.unofficial_count; + cheevo = rcheevos_locals.unofficial; + count = rcheevos_locals.patchdata.unofficial_count; } for (j = 0; j < count; j++, cheevo++) @@ -1050,7 +1050,7 @@ static void cheevos_unlock_cb(unsigned id, void* userdata) #ifndef CHEEVOS_DONT_DEACTIVATE cheevo->active &= ~*(unsigned*)userdata; #endif - CHEEVOS_LOG(CHEEVOS_TAG "cheevo %u deactivated: %s\n", id, cheevo->info->title); + CHEEVOS_LOG(RCHEEVOS_TAG "cheevo %u deactivated: %s\n", id, cheevo->info->title); return; } } @@ -1059,7 +1059,7 @@ static void cheevos_unlock_cb(unsigned id, void* userdata) #include "coro.h" -/* Uncomment the following two lines to debug cheevos_iterate, this will +/* Uncomment the following two lines to debug rcheevos_iterate, this will * disable the coroutine yielding. * * The code is very easy to understand. It's meant to be like BASIC: @@ -1093,7 +1093,7 @@ typedef struct size_t len; size_t size; MD5_CTX md5; - cheevos_nes_header_t header; + rcheevos_nes_header_t header; retro_time_t t0; struct retro_system_info sysinfo; void *data; @@ -1101,38 +1101,38 @@ typedef struct const char *path; const char *ext; intfstream_t *stream; - cheevos_cheevo_t *cheevo; + rcheevos_cheevo_t *cheevo; settings_t *settings; struct http_connection_t *conn; struct http_t *http; - const cheevos_cheevo_t *cheevo_end; + const rcheevos_cheevo_t *cheevo_end; /* co-routine required fields */ CORO_FIELDS -} coro_t; +} rcheevos_coro_t; enum { /* Negative values because CORO_SUB generates positive values */ - SNES_MD5 = -1, - GENESIS_MD5 = -2, - LYNX_MD5 = -3, - NES_MD5 = -4, - GENERIC_MD5 = -5, - FILENAME_MD5 = -6, - EVAL_MD5 = -7, - FILL_MD5 = -8, - GET_GAMEID = -9, - GET_CHEEVOS = -10, - GET_BADGES = -11, - LOGIN = -12, - HTTP_GET = -13, - DEACTIVATE = -14, - PLAYING = -15, - DELAY = -16 + RCHEEVOS_SNES_MD5 = -1, + RCHEEVOS_GENESIS_MD5 = -2, + RCHEEVOS_LYNX_MD5 = -3, + RCHEEVOS_NES_MD5 = -4, + RCHEEVOS_GENERIC_MD5 = -5, + RCHEEVOS_FILENAME_MD5 = -6, + RCHEEVOS_EVAL_MD5 = -7, + RCHEEVOS_FILL_MD5 = -8, + RCHEEVOS_GET_GAMEID = -9, + RCHEEVOS_GET_CHEEVOS = -10, + RCHEEVOS_GET_BADGES = -11, + RCHEEVOS_LOGIN = -12, + RCHEEVOS_HTTP_GET = -13, + RCHEEVOS_DEACTIVATE = -14, + RCHEEVOS_PLAYING = -15, + RCHEEVOS_DELAY = -16 }; -static int cheevos_iterate(coro_t* coro) +static int rcheevos_iterate(rcheevos_coro_t* coro) { const int snes_header_len = 0x200; const int lynx_header_len = 0x40; @@ -1175,14 +1175,14 @@ static int cheevos_iterate(coro_t* coro) 0 }; - static cheevos_finder_t finders[] = + static rcheevos_finder_t finders[] = { - {SNES_MD5, "SNES (discards header)", snes_exts}, - {GENESIS_MD5, "Genesis (6Mb padding)", genesis_exts}, - {LYNX_MD5, "Atari Lynx (discards header)", lynx_exts}, - {NES_MD5, "NES (discards header)", NULL}, - {GENERIC_MD5, "Generic (plain content)", NULL}, - {FILENAME_MD5, "Generic (filename)", NULL} + {RCHEEVOS_SNES_MD5, "SNES (discards header)", snes_exts}, + {RCHEEVOS_GENESIS_MD5, "Genesis (6Mb padding)", genesis_exts}, + {RCHEEVOS_LYNX_MD5, "Atari Lynx (discards header)", lynx_exts}, + {RCHEEVOS_NES_MD5, "NES (discards header)", NULL}, + {RCHEEVOS_GENERIC_MD5, "Generic (plain content)", NULL}, + {RCHEEVOS_FILENAME_MD5, "Generic (filename)", NULL} }; CORO_ENTER(); @@ -1268,12 +1268,12 @@ static int cheevos_iterate(coro_t* coro) if (end) { - hash = cheevos_djb2(coro->ext, end - coro->ext); + hash = rcheevos_djb2(coro->ext, end - coro->ext); coro->ext = end + 1; } else { - hash = cheevos_djb2(coro->ext, strlen(coro->ext)); + hash = rcheevos_djb2(coro->ext, strlen(coro->ext)); coro->ext = NULL; } @@ -1281,7 +1281,7 @@ static int cheevos_iterate(coro_t* coro) { if (finders[coro->i].ext_hashes[coro->j] == hash) { - CHEEVOS_LOG(CHEEVOS_TAG "testing %s\n", + CHEEVOS_LOG(RCHEEVOS_TAG "testing %s\n", finders[coro->i].name); /* @@ -1306,7 +1306,7 @@ static int cheevos_iterate(coro_t* coro) if (finders[coro->i].ext_hashes) continue; - CHEEVOS_LOG(CHEEVOS_TAG "testing %s\n", + CHEEVOS_LOG(RCHEEVOS_TAG "testing %s\n", finders[coro->i].name); /* @@ -1319,7 +1319,7 @@ static int cheevos_iterate(coro_t* coro) goto found; } - CHEEVOS_LOG(CHEEVOS_TAG "this game doesn't feature achievements\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "this game doesn't feature achievements\n"); CORO_STOP(); found: @@ -1340,12 +1340,12 @@ found: coro->json[size] = 0; } #else - CORO_GOSUB(GET_CHEEVOS); + CORO_GOSUB(RCHEEVOS_GET_CHEEVOS); if (!coro->json) { runloop_msg_queue_push("Error loading achievements.", 0, 5 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - CHEEVOS_ERR(CHEEVOS_TAG "error loading achievements\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "error loading achievements\n"); CORO_STOP(); } #endif @@ -1357,7 +1357,7 @@ found: fclose(file); } #endif - if (cheevos_parse(coro->json)) + if (rcheevos_parse(coro->json)) { CHEEVOS_FREE(coro->json); CORO_STOP(); @@ -1365,9 +1365,9 @@ found: CHEEVOS_FREE(coro->json); - if ( cheevos_locals.patchdata.core_count == 0 - && cheevos_locals.patchdata.unofficial_count == 0 - && cheevos_locals.patchdata.lboard_count == 0) + if ( rcheevos_locals.patchdata.core_count == 0 + && rcheevos_locals.patchdata.unofficial_count == 0 + && rcheevos_locals.patchdata.lboard_count == 0) { runloop_msg_queue_push( "This game has no achievements.", @@ -1376,30 +1376,35 @@ found: CORO_STOP(); } - cheevos_loaded = true; + rcheevos_loaded = true; /* * Inputs: CHEEVOS_VAR_GAMEID * Outputs: */ - CORO_GOSUB(DEACTIVATE); + CORO_GOSUB(RCHEEVOS_DEACTIVATE); /* * Inputs: CHEEVOS_VAR_GAMEID * Outputs: */ - CORO_GOSUB(PLAYING); + CORO_GOSUB(RCHEEVOS_PLAYING); - if (coro->settings->bools.cheevos_verbose_enable && cheevos_locals.patchdata.core_count > 0) + if (coro->settings->bools.cheevos_verbose_enable && rcheevos_locals.patchdata.core_count > 0) { char msg[256]; - int mode = CHEEVOS_ACTIVE_SOFTCORE; - const cheevos_cheevo_t* cheevo = cheevos_locals.core; - const cheevos_cheevo_t* end = cheevo + cheevos_locals.patchdata.core_count; - int number_of_unlocked = cheevos_locals.patchdata.core_count; + int mode = RCHEEVOS_ACTIVE_SOFTCORE; + const rcheevos_cheevo_t* cheevo = rcheevos_locals.core; + const rcheevos_cheevo_t* end = cheevo + rcheevos_locals.patchdata.core_count; + int number_of_unlocked = rcheevos_locals.patchdata.core_count; - if (coro->settings->bools.cheevos_hardcore_mode_enable && !cheevos_hardcore_paused) - mode = CHEEVOS_ACTIVE_HARDCORE; + /* RCHEEVOS TODO: remove this msg */ + snprintf(msg, sizeof(msg), "cheevos: using the new implementation."); + msg[sizeof(msg) - 1] = 0; + runloop_msg_queue_push(msg, 0, 3 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + + if (coro->settings->bools.cheevos_hardcore_mode_enable && !rcheevos_hardcore_paused) + mode = RCHEEVOS_ACTIVE_HARDCORE; for (; cheevo < end; cheevo++) if (cheevo->active & mode) @@ -1407,12 +1412,12 @@ found: snprintf(msg, sizeof(msg), "You have %d of %d achievements unlocked.", - number_of_unlocked, cheevos_locals.patchdata.core_count); + number_of_unlocked, rcheevos_locals.patchdata.core_count); msg[sizeof(msg) - 1] = 0; runloop_msg_queue_push(msg, 0, 6 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } - CORO_GOSUB(GET_BADGES); + CORO_GOSUB(RCHEEVOS_GET_BADGES); CORO_STOP(); /************************************************************************** @@ -1420,11 +1425,11 @@ found: * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(SNES_MD5) + CORO_SUB(RCHEEVOS_SNES_MD5) MD5_Init(&coro->md5); /* Checks for the existence of a headered SNES file. - Unheadered files fall back to GENERIC_MD5. */ + Unheadered files fall back to RCHEEVOS_GENERIC_MD5. */ if (coro->len < 0x2000 || coro->len % 0x2000 != snes_header_len) { coro->gameid = 0; @@ -1434,23 +1439,23 @@ found: coro->offset = snes_header_len; coro->count = 0; - CORO_GOSUB(EVAL_MD5); + CORO_GOSUB(RCHEEVOS_EVAL_MD5); MD5_Final(coro->hash, &coro->md5); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); /************************************************************************** * Info Tries to identify a Genesis game * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(GENESIS_MD5) + CORO_SUB(RCHEEVOS_GENESIS_MD5) MD5_Init(&coro->md5); coro->offset = 0; coro->count = 0; - CORO_GOSUB(EVAL_MD5); + CORO_GOSUB(RCHEEVOS_EVAL_MD5); if (coro->count == 0) { @@ -1463,21 +1468,21 @@ found: { coro->offset = 0; coro->count = CHEEVOS_MB(6) - coro->count; - CORO_GOSUB(FILL_MD5); + CORO_GOSUB(RCHEEVOS_FILL_MD5); } MD5_Final(coro->hash, &coro->md5); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); /************************************************************************** * Info Tries to identify an Atari Lynx game * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(LYNX_MD5) + CORO_SUB(RCHEEVOS_LYNX_MD5) /* Checks for the existence of a headered Lynx file. - Unheadered files fall back to GENERIC_MD5. */ + Unheadered files fall back to RCHEEVOS_GENERIC_MD5. */ if (coro->len <= lynx_header_len || memcmp("LYNX", (void *)coro->data, 5) != 0) { @@ -1488,20 +1493,20 @@ found: MD5_Init(&coro->md5); coro->offset = lynx_header_len; coro->count = coro->len - lynx_header_len; - CORO_GOSUB(EVAL_MD5); + CORO_GOSUB(RCHEEVOS_EVAL_MD5); MD5_Final(coro->hash, &coro->md5); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); /************************************************************************** * Info Tries to identify a NES game * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(NES_MD5) + CORO_SUB(RCHEEVOS_NES_MD5) /* Checks for the existence of a headered NES file. - Unheadered files fall back to GENERIC_MD5. */ + Unheadered files fall back to RCHEEVOS_GENERIC_MD5. */ if (coro->len < sizeof(coro->header)) { coro->gameid = 0; @@ -1523,37 +1528,37 @@ found: MD5_Init(&coro->md5); coro->offset = sizeof(coro->header); coro->count = coro->len - coro->offset; - CORO_GOSUB(EVAL_MD5); + CORO_GOSUB(RCHEEVOS_EVAL_MD5); MD5_Final(coro->hash, &coro->md5); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); /************************************************************************** * Info Tries to identify a "generic" game * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(GENERIC_MD5) + CORO_SUB(RCHEEVOS_GENERIC_MD5) MD5_Init(&coro->md5); coro->offset = 0; coro->count = 0; - CORO_GOSUB(EVAL_MD5); + CORO_GOSUB(RCHEEVOS_EVAL_MD5); MD5_Final(coro->hash, &coro->md5); if (coro->count == 0) CORO_RET(); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); /************************************************************************** * Info Tries to identify a game based on its filename (with no extension) * Input CHEEVOS_VAR_INFO the content info * Output CHEEVOS_VAR_GAMEID the Retro Achievements game ID, or 0 if not found *************************************************************************/ - CORO_SUB(FILENAME_MD5) + CORO_SUB(RCHEEVOS_FILENAME_MD5) if (!string_is_empty(coro->path)) { char base_noext[PATH_MAX_LENGTH]; @@ -1563,7 +1568,7 @@ found: MD5_Update(&coro->md5, (void*)base_noext, strlen(base_noext)); MD5_Final(coro->hash, &coro->md5); - CORO_GOTO(GET_GAMEID); + CORO_GOTO(RCHEEVOS_GET_GAMEID); } CORO_RET(); @@ -1572,7 +1577,7 @@ found: * Inputs CHEEVOS_VAR_INFO, CHEEVOS_VAR_OFFSET, CHEEVOS_VAR_COUNT * Outputs CHEEVOS_VAR_MD5, CHEEVOS_VAR_COUNT *************************************************************************/ - CORO_SUB(EVAL_MD5) + CORO_SUB(RCHEEVOS_EVAL_MD5) if (coro->count == 0) coro->count = coro->len; @@ -1594,7 +1599,7 @@ found: * Inputs CHEEVOS_VAR_OFFSET, CHEEVOS_VAR_COUNT * Outputs CHEEVOS_VAR_MD5 *************************************************************************/ - CORO_SUB(FILL_MD5) + CORO_SUB(RCHEEVOS_FILL_MD5) { char buffer[4096]; @@ -1619,19 +1624,19 @@ found: * Inputs coro->hash * Outputs CHEEVOS_VAR_GAMEID *************************************************************************/ - CORO_SUB(GET_GAMEID) + CORO_SUB(RCHEEVOS_GET_GAMEID) { int size = rc_url_get_gameid(coro->url, sizeof(coro->url), coro->hash); if (size < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "buffer too small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n"); CORO_RET(); } - cheevos_log_url(CHEEVOS_TAG "rc_url_get_gameid: %s\n", coro->url); - CORO_GOSUB(HTTP_GET); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_get_gameid: %s\n", coro->url); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (!coro->json) CORO_RET(); @@ -1639,7 +1644,7 @@ found: coro->gameid = chevos_get_gameid(coro->json); CHEEVOS_FREE(coro->json); - CHEEVOS_LOG(CHEEVOS_TAG "got game id %u\n", coro->gameid); + CHEEVOS_LOG(RCHEEVOS_TAG "got game id %u\n", coro->gameid); CORO_RET(); } @@ -1648,30 +1653,30 @@ found: * Inputs CHEEVOS_VAR_GAMEID * Outputs CHEEVOS_VAR_JSON *************************************************************************/ - CORO_SUB(GET_CHEEVOS) + CORO_SUB(RCHEEVOS_GET_CHEEVOS) { int ret; - CORO_GOSUB(LOGIN); + CORO_GOSUB(RCHEEVOS_LOGIN); - ret = rc_url_get_patch(coro->url, sizeof(coro->url), coro->settings->arrays.cheevos_username, cheevos_locals.token, coro->gameid); + ret = rc_url_get_patch(coro->url, sizeof(coro->url), coro->settings->arrays.cheevos_username, rcheevos_locals.token, coro->gameid); if (ret < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "buffer too small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n"); CORO_STOP(); } - cheevos_log_url(CHEEVOS_TAG "rc_url_get_patch: %s\n", coro->url); - CORO_GOSUB(HTTP_GET); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_get_patch: %s\n", coro->url); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (!coro->json) { - CHEEVOS_ERR(CHEEVOS_TAG "error getting achievements for game id %u\n", coro->gameid); + CHEEVOS_ERR(RCHEEVOS_TAG "error getting achievements for game id %u\n", coro->gameid); CORO_STOP(); } - CHEEVOS_LOG(CHEEVOS_TAG "got achievements for game id %u\n", coro->gameid); + CHEEVOS_LOG(RCHEEVOS_TAG "got achievements for game id %u\n", coro->gameid); CORO_RET(); } @@ -1680,7 +1685,7 @@ found: * Inputs CHEEVOS_VAR_GAMEID * Outputs CHEEVOS_VAR_JSON *************************************************************************/ - CORO_SUB(GET_BADGES) + CORO_SUB(RCHEEVOS_GET_BADGES) badges_ctx = new_badges_ctx; @@ -1701,13 +1706,13 @@ found: { if (coro->i == 0) { - coro->cheevo = cheevos_locals.core; - coro->cheevo_end = coro->cheevo + cheevos_locals.patchdata.core_count; + coro->cheevo = rcheevos_locals.core; + coro->cheevo_end = coro->cheevo + rcheevos_locals.patchdata.core_count; } else { - coro->cheevo = cheevos_locals.unofficial; - coro->cheevo_end = coro->cheevo + cheevos_locals.patchdata.unofficial_count; + coro->cheevo = rcheevos_locals.unofficial; + coro->cheevo_end = coro->cheevo + rcheevos_locals.patchdata.unofficial_count; } for (; coro->cheevo < coro->cheevo_end; coro->cheevo++) @@ -1742,7 +1747,7 @@ found: { #ifdef CHEEVOS_LOG_BADGES CHEEVOS_LOG( - CHEEVOS_TAG "downloading badge %s\n", + RCHEEVOS_TAG "downloading badge %s\n", coro->badge_fullpath); #endif snprintf(coro->url, @@ -1750,13 +1755,13 @@ found: "http://i.retroachievements.org/Badge/%s", coro->badge_name); - CORO_GOSUB(HTTP_GET); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (coro->json) { if (!filestream_write_file(coro->badge_fullpath, coro->json, coro->k)) - CHEEVOS_ERR(CHEEVOS_TAG "error writing badge %s\n", coro->badge_fullpath); + CHEEVOS_ERR(RCHEEVOS_TAG "error writing badge %s\n", coro->badge_fullpath); else CHEEVOS_FREE(coro->json); } @@ -1770,7 +1775,7 @@ found: /************************************************************************** * Info Logs in the user at Retro Achievements *************************************************************************/ - CORO_SUB(LOGIN) + CORO_SUB(RCHEEVOS_LOGIN) { const char* username = coro->settings->arrays.cheevos_username; const char* password = coro->settings->arrays.cheevos_password; @@ -1778,7 +1783,7 @@ found: int ret; char tok[256]; - if (cheevos_locals.token[0]) + if (rcheevos_locals.token[0]) CORO_RET(); if (string_is_empty(username)) @@ -1789,7 +1794,7 @@ found: runloop_msg_queue_push( "Please fill in your account information in Settings.", 0, 5 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - CHEEVOS_ERR(CHEEVOS_TAG "login info not informed\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "login info not informed\n"); CORO_STOP(); } @@ -1802,22 +1807,22 @@ found: if (ret < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "buffer too small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n"); CORO_STOP(); } - cheevos_log_url(CHEEVOS_TAG "rc_url_login_with_password: %s\n", coro->url); - CORO_GOSUB(HTTP_GET); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_login_with_password: %s\n", coro->url); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (!coro->json) { runloop_msg_queue_push("RetroAchievements: Error contacting server.", 0, 5 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); - CHEEVOS_ERR(CHEEVOS_TAG "error getting user token\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "error getting user token\n"); CORO_STOP(); } - ret = cheevos_get_token(coro->json, tok, sizeof(tok)); + ret = rcheevos_get_token(coro->json, tok, sizeof(tok)); if (ret != 0) { @@ -1844,8 +1849,8 @@ found: runloop_msg_queue_push(msg, 0, 3 * 60, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } - strlcpy(cheevos_locals.token, tok, - sizeof(cheevos_locals.token)); + strlcpy(rcheevos_locals.token, tok, + sizeof(rcheevos_locals.token)); /* Save token to config and clear pass on success */ strlcpy(coro->settings->arrays.cheevos_token, tok, @@ -1858,7 +1863,7 @@ found: /************************************************************************** * Info Pauses execution for five seconds *************************************************************************/ - CORO_SUB(DELAY) + CORO_SUB(RCHEEVOS_DELAY) { retro_time_t t1; @@ -1878,12 +1883,12 @@ found: * Inputs CHEEVOS_VAR_URL * Outputs CHEEVOS_VAR_JSON *************************************************************************/ - CORO_SUB(HTTP_GET) + CORO_SUB(RCHEEVOS_HTTP_GET) for (coro->k = 0; coro->k < 5; coro->k++) { if (coro->k != 0) - CHEEVOS_LOG(CHEEVOS_TAG "Retrying HTTP request: %u of 5\n", coro->k + 1); + CHEEVOS_LOG(RCHEEVOS_TAG "Retrying HTTP request: %u of 5\n", coro->k + 1); coro->json = NULL; coro->conn = net_http_connection_new( @@ -1891,7 +1896,7 @@ found: if (!coro->conn) { - CORO_GOSUB(DELAY); + CORO_GOSUB(RCHEEVOS_DELAY); continue; } @@ -1911,7 +1916,7 @@ found: if (!coro->http) { net_http_connection_free(coro->conn); - CORO_GOSUB(DELAY); + CORO_GOSUB(RCHEEVOS_DELAY); continue; } @@ -1945,7 +1950,7 @@ found: net_http_connection_free(coro->conn); } - CHEEVOS_LOG(CHEEVOS_TAG "Couldn't connect to server after 5 tries\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "Couldn't connect to server after 5 tries\n"); CORO_RET(); /************************************************************************** @@ -1953,34 +1958,34 @@ found: * Inputs CHEEVOS_VAR_GAMEID * Outputs *************************************************************************/ - CORO_SUB(DEACTIVATE) + CORO_SUB(RCHEEVOS_DEACTIVATE) - CORO_GOSUB(LOGIN); + CORO_GOSUB(RCHEEVOS_LOGIN); { int ret; unsigned mode; for (coro->i = 0; coro->i < 2; coro->i++) { - ret = rc_url_get_unlock_list(coro->url, sizeof(coro->url), coro->settings->arrays.cheevos_username, cheevos_locals.token, coro->gameid, coro->i); + ret = rc_url_get_unlock_list(coro->url, sizeof(coro->url), coro->settings->arrays.cheevos_username, rcheevos_locals.token, coro->gameid, coro->i); if (ret < 0) { - CHEEVOS_ERR(CHEEVOS_TAG "buffer too small to create URL\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n"); CORO_STOP(); } - cheevos_log_url(CHEEVOS_TAG "rc_url_get_unlock_list: %s\n", coro->url); - CORO_GOSUB(HTTP_GET); + rcheevos_log_url(RCHEEVOS_TAG "rc_url_get_unlock_list: %s\n", coro->url); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (coro->json) { - mode = coro->i == 0 ? CHEEVOS_ACTIVE_SOFTCORE : CHEEVOS_ACTIVE_HARDCORE; - cheevos_deactivate_unlocks(coro->json, cheevos_unlock_cb, &mode); + mode = coro->i == 0 ? RCHEEVOS_ACTIVE_SOFTCORE : RCHEEVOS_ACTIVE_HARDCORE; + rcheevos_deactivate_unlocks(coro->json, rcheevos_unlock_cb, &mode); CHEEVOS_FREE(coro->json); } else - CHEEVOS_ERR(CHEEVOS_TAG "error retrieving list of unlocked achievements in softcore mode\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "error retrieving list of unlocked achievements in softcore mode\n"); } } @@ -1991,56 +1996,56 @@ found: * Inputs CHEEVOS_VAR_GAMEID * Outputs *************************************************************************/ - CORO_SUB(PLAYING) + CORO_SUB(RCHEEVOS_PLAYING) snprintf( coro->url, sizeof(coro->url), "http://retroachievements.org/dorequest.php?r=postactivity&u=%s&t=%s&a=3&m=%u", coro->settings->arrays.cheevos_username, - cheevos_locals.token, coro->gameid + rcheevos_locals.token, coro->gameid ); coro->url[sizeof(coro->url) - 1] = 0; - cheevos_log_url(CHEEVOS_TAG "url to post the 'playing' activity: %s\n", coro->url); + rcheevos_log_url(RCHEEVOS_TAG "url to post the 'playing' activity: %s\n", coro->url); - CORO_GOSUB(HTTP_GET); + CORO_GOSUB(RCHEEVOS_HTTP_GET); if (coro->json) { - CHEEVOS_LOG(CHEEVOS_TAG "posted playing activity\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "posted playing activity\n"); CHEEVOS_FREE(coro->json); } else - CHEEVOS_ERR(CHEEVOS_TAG "error posting playing activity\n"); + CHEEVOS_ERR(RCHEEVOS_TAG "error posting playing activity\n"); - CHEEVOS_LOG(CHEEVOS_TAG "posted playing activity\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "posted playing activity\n"); CORO_RET(); CORO_LEAVE(); } -static void cheevos_task_handler(retro_task_t *task) +static void rcheevos_task_handler(retro_task_t *task) { - coro_t *coro = (coro_t*)task->state; + rcheevos_coro_t *coro = (rcheevos_coro_t*)task->state; if (!coro) return; - if (!cheevos_iterate(coro) || task_get_cancelled(task)) + if (!rcheevos_iterate(coro) || task_get_cancelled(task)) { task_set_finished(task, true); - CHEEVOS_LOCK(cheevos_locals.task_lock); - cheevos_locals.task = NULL; - CHEEVOS_UNLOCK(cheevos_locals.task_lock); + CHEEVOS_LOCK(rcheevos_locals.task_lock); + rcheevos_locals.task = NULL; + CHEEVOS_UNLOCK(rcheevos_locals.task_lock); if (task_get_cancelled(task)) { - CHEEVOS_LOG(CHEEVOS_TAG "Load task cancelled\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "Load task cancelled\n"); } else { - CHEEVOS_LOG(CHEEVOS_TAG "Load task finished\n"); + CHEEVOS_LOG(RCHEEVOS_TAG "Load task finished\n"); } CHEEVOS_FREE(coro->data); @@ -2049,19 +2054,19 @@ static void cheevos_task_handler(retro_task_t *task) } } -bool cheevos_load(const void *data) +bool rcheevos_load(const void *data) { retro_task_t *task; const struct retro_game_info *info = NULL; - coro_t *coro = NULL; + rcheevos_coro_t *coro = NULL; - cheevos_loaded = false; - cheevos_hardcore_paused = false; + rcheevos_loaded = false; + rcheevos_hardcore_paused = false; - if (!cheevos_locals.core_supports || !data) + if (!rcheevos_locals.core_supports || !data) return false; - coro = (coro_t*)calloc(1, sizeof(*coro)); + coro = (rcheevos_coro_t*)calloc(1, sizeof(*coro)); if (!coro) return false; @@ -2104,7 +2109,7 @@ bool cheevos_load(const void *data) coro->path = strdup(info->path); } - task->handler = cheevos_task_handler; + task->handler = rcheevos_task_handler; task->state = (void*)coro; task->mute = true; task->callback = NULL; @@ -2113,15 +2118,15 @@ bool cheevos_load(const void *data) task->title = NULL; #ifdef HAVE_THREADS - if (cheevos_locals.task_lock == NULL) + if (rcheevos_locals.task_lock == NULL) { - cheevos_locals.task_lock = slock_new(); + rcheevos_locals.task_lock = slock_new(); } #endif - CHEEVOS_LOCK(cheevos_locals.task_lock); - cheevos_locals.task = task; - CHEEVOS_UNLOCK(cheevos_locals.task_lock); + CHEEVOS_LOCK(rcheevos_locals.task_lock); + rcheevos_locals.task = task; + CHEEVOS_UNLOCK(rcheevos_locals.task_lock); task_queue_push(task); diff --git a/cheevos-new/cheevos.h b/cheevos-new/cheevos.h index 65aaabc31b..fce51e482c 100644 --- a/cheevos-new/cheevos.h +++ b/cheevos-new/cheevos.h @@ -27,49 +27,49 @@ RETRO_BEGIN_DECLS -typedef struct cheevos_ctx_desc +typedef struct rcheevos_ctx_desc { unsigned idx; char *s; size_t len; -} cheevos_ctx_desc_t; +} rcheevos_ctx_desc_t; enum { - CHEEVOS_ACTIVE_SOFTCORE = 1 << 0, - CHEEVOS_ACTIVE_HARDCORE = 1 << 1 + RCHEEVOS_ACTIVE_SOFTCORE = 1 << 0, + RCHEEVOS_ACTIVE_HARDCORE = 1 << 1 }; -bool cheevos_load(const void *data); +bool rcheevos_load(const void *data); -void cheevos_reset_game(void); +void rcheevos_reset_game(void); -void cheevos_populate_menu(void *data); +void rcheevos_populate_menu(void *data); -bool cheevos_get_description(cheevos_ctx_desc_t *desc); +bool rcheevos_get_description(rcheevos_ctx_desc_t *desc); -bool cheevos_apply_cheats(bool *data_bool); +bool rcheevos_apply_cheats(bool *data_bool); -bool cheevos_unload(void); +bool rcheevos_unload(void); -bool cheevos_toggle_hardcore_mode(void); +bool rcheevos_toggle_hardcore_mode(void); -void cheevos_test(void); +void rcheevos_test(void); -bool cheevos_set_cheats(void); +bool rcheevos_set_cheats(void); -void cheevos_set_support_cheevos(bool state); +void rcheevos_set_support_cheevos(bool state); -bool cheevos_get_support_cheevos(void); +bool rcheevos_get_support_cheevos(void); -int cheevos_get_console(void); +int rcheevos_get_console(void); -extern bool cheevos_loaded; -extern bool cheevos_hardcore_active; -extern bool cheevos_hardcore_paused; -extern bool cheevos_state_loaded_flag; -extern int cheats_are_enabled; -extern int cheats_were_enabled; +extern bool rcheevos_loaded; +extern bool rcheevos_hardcore_active; +extern bool rcheevos_hardcore_paused; +extern bool rcheevos_state_loaded_flag; +extern int rcheevos_cheats_are_enabled; +extern int rcheevos_cheats_were_enabled; RETRO_END_DECLS diff --git a/cheevos-new/coro.h b/cheevos-new/coro.h index a9eb7a4c8b..e81e77e7c1 100644 --- a/cheevos-new/coro.h +++ b/cheevos-new/coro.h @@ -5,7 +5,7 @@ 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 */ +/* Use at the beginning of the coroutine, you must have declared a variable rcheevos_coro_t* coro */ #define CORO_ENTER() \ { \ CORO_again: ; \ @@ -67,7 +67,7 @@ Released under the CC0: https://creativecommons.org/publicdomain/zero/1.0/ return 0; \ } while ( 0 ) -/* Add this macro to your coro_t structure containing the variables for the coroutine */ +/* Add this macro to your rcheevos_coro_t structure containing the variables for the coroutine */ #define CORO_FIELDS \ int step, sp; \ int stack[ 8 ]; diff --git a/cheevos-new/fixup.c b/cheevos-new/fixup.c index 56e0436cb6..12c52b822a 100644 --- a/cheevos-new/fixup.c +++ b/cheevos-new/fixup.c @@ -22,10 +22,10 @@ #include -static int cheevos_cmpaddr(const void* e1, const void* e2) +static int rcheevos_cmpaddr(const void* e1, const void* e2) { - const cheevos_fixup_t* f1 = (const cheevos_fixup_t*)e1; - const cheevos_fixup_t* f2 = (const cheevos_fixup_t*)e2; + const rcheevos_fixup_t* f1 = (const rcheevos_fixup_t*)e1; + const rcheevos_fixup_t* f2 = (const rcheevos_fixup_t*)e2; if (f1->address < f2->address) { @@ -41,7 +41,7 @@ static int cheevos_cmpaddr(const void* e1, const void* e2) } } -static size_t cheevos_var_reduce(size_t addr, size_t mask) +static size_t rcheevos_var_reduce(size_t addr, size_t mask) { while (mask) { @@ -53,7 +53,7 @@ static size_t cheevos_var_reduce(size_t addr, size_t mask) return addr; } -static size_t cheevos_var_highest_bit(size_t n) +static size_t rcheevos_var_highest_bit(size_t n) { n |= n >> 1; n |= n >> 2; @@ -64,33 +64,33 @@ static size_t cheevos_var_highest_bit(size_t n) return n ^ (n >> 1); } -void cheevos_fixup_init(cheevos_fixups_t* fixups) +void rcheevos_fixup_init(rcheevos_fixups_t* fixups) { fixups->elements = NULL; fixups->capacity = fixups->count = 0; fixups->dirty = false; } -void cheevos_fixup_destroy(cheevos_fixups_t* fixups) +void rcheevos_fixup_destroy(rcheevos_fixups_t* fixups) { CHEEVOS_FREE(fixups->elements); - cheevos_fixup_init(fixups); + rcheevos_fixup_init(fixups); } -const uint8_t* cheevos_fixup_find(cheevos_fixups_t* fixups, unsigned address, int console) +const uint8_t* rcheevos_fixup_find(rcheevos_fixups_t* fixups, unsigned address, int console) { - cheevos_fixup_t key; - cheevos_fixup_t* found; + rcheevos_fixup_t key; + rcheevos_fixup_t* found; const uint8_t* location; if (fixups->dirty) { - qsort(fixups->elements, fixups->count, sizeof(cheevos_fixup_t), cheevos_cmpaddr); + qsort(fixups->elements, fixups->count, sizeof(rcheevos_fixup_t), rcheevos_cmpaddr); fixups->dirty = false; } key.address = address; - found = (cheevos_fixup_t*)bsearch(&key, fixups->elements, fixups->count, sizeof(cheevos_fixup_t), cheevos_cmpaddr); + found = (rcheevos_fixup_t*)bsearch(&key, fixups->elements, fixups->count, sizeof(rcheevos_fixup_t), rcheevos_cmpaddr); if (found != NULL) { @@ -100,8 +100,8 @@ const uint8_t* cheevos_fixup_find(cheevos_fixups_t* fixups, unsigned address, in if (fixups->count == fixups->capacity) { unsigned new_capacity = fixups->capacity == 0 ? 16 : fixups->capacity * 2; - cheevos_fixup_t* new_elements = (cheevos_fixup_t*) - realloc(fixups->elements, new_capacity * sizeof(cheevos_fixup_t)); + rcheevos_fixup_t* new_elements = (rcheevos_fixup_t*) + realloc(fixups->elements, new_capacity * sizeof(rcheevos_fixup_t)); if (new_elements == NULL) { @@ -114,13 +114,13 @@ const uint8_t* cheevos_fixup_find(cheevos_fixups_t* fixups, unsigned address, in fixups->elements[fixups->count].address = address; fixups->elements[fixups->count++].location = location = - cheevos_patch_address(address, console); + rcheevos_patch_address(address, console); fixups->dirty = true; return location; } -const uint8_t* cheevos_patch_address(unsigned address, int console) +const uint8_t* rcheevos_patch_address(unsigned address, int console) { rarch_system_info_t* system = runloop_get_system_info(); const void* pointer = NULL; @@ -130,7 +130,7 @@ const uint8_t* cheevos_patch_address(unsigned address, int console) if (address >= 0x0800 && address < 0x2000) { /* Address in the mirrorred RAM, adjust to real RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "NES memory address in mirrorred RAM %X, adjusted to %X\n", address, address & 0x07ff); + CHEEVOS_LOG(RCHEEVOS_TAG "NES memory address in mirrorred RAM %X, adjusted to %X\n", address, address & 0x07ff); address &= 0x07ff; } } @@ -139,7 +139,7 @@ const uint8_t* cheevos_patch_address(unsigned address, int console) if (address >= 0xe000 && address <= 0xfdff) { /* Address in the echo RAM, adjust to real RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "GBC memory address in echo RAM %X, adjusted to %X\n", address, address - 0x2000); + CHEEVOS_LOG(RCHEEVOS_TAG "GBC memory address in echo RAM %X, adjusted to %X\n", address, address - 0x2000); address -= 0x2000; } } @@ -156,20 +156,20 @@ const uint8_t* cheevos_patch_address(unsigned address, int console) if (address < 0x8000) { /* Internal RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "GBA memory address %X adjusted to %X\n", address, address + 0x3000000); + CHEEVOS_LOG(RCHEEVOS_TAG "GBA memory address %X adjusted to %X\n", address, address + 0x3000000); address += 0x3000000; } else { /* Work RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "GBA memory address %X adjusted to %X\n", address, address + 0x2000000 - 0x8000); + CHEEVOS_LOG(RCHEEVOS_TAG "GBA memory address %X adjusted to %X\n", address, address + 0x2000000 - 0x8000); address += 0x2000000 - 0x8000; } } else if (console == RC_CONSOLE_PC_ENGINE) { /* RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "PCE memory address %X adjusted to %X\n", address, address + 0x1f0000); + CHEEVOS_LOG(RCHEEVOS_TAG "PCE memory address %X adjusted to %X\n", address, address + 0x1f0000); address += 0x1f0000; } else if (console == RC_CONSOLE_SUPER_NINTENDO) @@ -177,13 +177,13 @@ const uint8_t* cheevos_patch_address(unsigned address, int console) if (address < 0x020000) { /* Work RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "SNES memory address %X adjusted to %X\n", address, address + 0x7e0000); + CHEEVOS_LOG(RCHEEVOS_TAG "SNES memory address %X adjusted to %X\n", address, address + 0x7e0000); address += 0x7e0000; } else { /* Save RAM. */ - CHEEVOS_LOG(CHEEVOS_TAG "SNES memory address %X adjusted to %X\n", address, address + 0x006000 - 0x020000); + CHEEVOS_LOG(RCHEEVOS_TAG "SNES memory address %X adjusted to %X\n", address, address + 0x006000 - 0x020000); address += 0x006000 - 0x020000; } } @@ -198,16 +198,16 @@ const uint8_t* cheevos_patch_address(unsigned address, int console) unsigned addr = address; pointer = desc->core.ptr; - address = (unsigned)cheevos_var_reduce( + address = (unsigned)rcheevos_var_reduce( (addr - desc->core.start) & desc->disconnect_mask, desc->core.disconnect); if (address >= desc->core.len) - address -= cheevos_var_highest_bit(address); + address -= rcheevos_var_highest_bit(address); address += desc->core.offset; - CHEEVOS_LOG(CHEEVOS_TAG "address %X set to descriptor %d at offset %X\n", addr, (int)((desc - system->mmaps.descriptors) + 1), address); + CHEEVOS_LOG(RCHEEVOS_TAG "address %X set to descriptor %d at offset %X\n", addr, (int)((desc - system->mmaps.descriptors) + 1), address); break; } } diff --git a/cheevos-new/fixup.h b/cheevos-new/fixup.h index 41893a0ba8..c0021fb6d9 100644 --- a/cheevos-new/fixup.h +++ b/cheevos-new/fixup.h @@ -27,21 +27,21 @@ typedef struct { unsigned address; const uint8_t* location; -} cheevos_fixup_t; +} rcheevos_fixup_t; typedef struct { - cheevos_fixup_t* elements; + rcheevos_fixup_t* elements; unsigned capacity, count; bool dirty; -} cheevos_fixups_t; +} rcheevos_fixups_t; -void cheevos_fixup_init(cheevos_fixups_t* fixups); -void cheevos_fixup_destroy(cheevos_fixups_t* fixups); +void rcheevos_fixup_init(rcheevos_fixups_t* fixups); +void rcheevos_fixup_destroy(rcheevos_fixups_t* fixups); -const uint8_t* cheevos_fixup_find(cheevos_fixups_t* fixups, unsigned address, int console); +const uint8_t* rcheevos_fixup_find(rcheevos_fixups_t* fixups, unsigned address, int console); -const uint8_t* cheevos_patch_address(unsigned address, int console); +const uint8_t* rcheevos_patch_address(unsigned address, int console); RETRO_END_DECLS diff --git a/cheevos-new/hash.c b/cheevos-new/hash.c index 7b84bbbc62..07d028a7f4 100644 --- a/cheevos-new/hash.c +++ b/cheevos-new/hash.c @@ -1,6 +1,6 @@ #include "hash.h" -uint32_t cheevos_djb2(const char* str, size_t length) +uint32_t rcheevos_djb2(const char* str, size_t length) { const unsigned char* aux = (const unsigned char*)str; uint32_t hash = 5381; diff --git a/cheevos-new/hash.h b/cheevos-new/hash.h index ec6e802947..c13b5ecde7 100644 --- a/cheevos-new/hash.h +++ b/cheevos-new/hash.h @@ -23,7 +23,7 @@ RETRO_BEGIN_DECLS -uint32_t cheevos_djb2(const char* str, size_t length); +uint32_t rcheevos_djb2(const char* str, size_t length); RETRO_END_DECLS diff --git a/cheevos-new/parser.c b/cheevos-new/parser.c index 19c503139d..38ec776089 100644 --- a/cheevos-new/parser.c +++ b/cheevos-new/parser.c @@ -38,21 +38,21 @@ typedef struct int is_key; const char* value; size_t length; -} cheevos_getvalueud_t; +} rcheevos_getvalueud_t; -static int cheevos_getvalue_key(void* userdata, +static int rcheevos_getvalue_key(void* userdata, const char* name, size_t length) { - cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata; + rcheevos_getvalueud_t* ud = (rcheevos_getvalueud_t*)userdata; - ud->is_key = cheevos_djb2(name, length) == ud->key_hash; + ud->is_key = rcheevos_djb2(name, length) == ud->key_hash; return 0; } -static int cheevos_getvalue_string(void* userdata, +static int rcheevos_getvalue_string(void* userdata, const char* string, size_t length) { - cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata; + rcheevos_getvalueud_t* ud = (rcheevos_getvalueud_t*)userdata; if (ud->is_key) { @@ -64,9 +64,9 @@ static int cheevos_getvalue_string(void* userdata, return 0; } -static int cheevos_getvalue_boolean(void* userdata, int istrue) +static int rcheevos_getvalue_boolean(void* userdata, int istrue) { - cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata; + rcheevos_getvalueud_t* ud = (rcheevos_getvalueud_t*)userdata; if (ud->is_key) { @@ -87,9 +87,9 @@ static int cheevos_getvalue_boolean(void* userdata, int istrue) return 0; } -static int cheevos_getvalue_null(void* userdata) +static int rcheevos_getvalue_null(void* userdata) { - cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata; + rcheevos_getvalueud_t* ud = (rcheevos_getvalueud_t*)userdata; if (ud->is_key ) { @@ -101,7 +101,7 @@ static int cheevos_getvalue_null(void* userdata) return 0; } -static int cheevos_get_value(const char* json, unsigned key_hash, +static int rcheevos_get_value(const char* json, unsigned key_hash, char* value, size_t length) { static const jsonsax_handlers_t handlers = @@ -112,15 +112,15 @@ static int cheevos_get_value(const char* json, unsigned key_hash, NULL, NULL, NULL, - cheevos_getvalue_key, + rcheevos_getvalue_key, NULL, - cheevos_getvalue_string, - cheevos_getvalue_string, /* number */ - cheevos_getvalue_boolean, - cheevos_getvalue_null + rcheevos_getvalue_string, + rcheevos_getvalue_string, /* number */ + rcheevos_getvalue_boolean, + rcheevos_getvalue_null }; - cheevos_getvalueud_t ud; + rcheevos_getvalueud_t ud; ud.key_hash = key_hash; ud.is_key = 0; @@ -142,14 +142,14 @@ static int cheevos_get_value(const char* json, unsigned key_hash, Returns the token of the error message *****************************************************************************/ -int cheevos_get_token(const char* json, char* token, size_t length) +int rcheevos_get_token(const char* json, char* token, size_t length) { - cheevos_get_value(json, CHEEVOS_JSON_KEY_ERROR, token, length); + rcheevos_get_value(json, CHEEVOS_JSON_KEY_ERROR, token, length); if (!string_is_empty(token)) return -1; - return cheevos_get_value(json, CHEEVOS_JSON_KEY_TOKEN, token, length); + return rcheevos_get_value(json, CHEEVOS_JSON_KEY_TOKEN, token, length); } /***************************************************************************** @@ -164,23 +164,23 @@ typedef struct unsigned core_count; unsigned unofficial_count; unsigned lboard_count; -} cheevos_countud_t; +} rcheevos_countud_t; -static int cheevos_count_end_array(void* userdata) +static int rcheevos_count_end_array(void* userdata) { - cheevos_countud_t* ud = (cheevos_countud_t*)userdata; + rcheevos_countud_t* ud = (rcheevos_countud_t*)userdata; ud->in_cheevos = 0; ud->in_lboards = 0; return 0; } -static int cheevos_count_key(void* userdata, +static int rcheevos_count_key(void* userdata, const char* name, size_t length) { - cheevos_countud_t* ud = (cheevos_countud_t*)userdata; + rcheevos_countud_t* ud = (rcheevos_countud_t*)userdata; - ud->field_hash = cheevos_djb2(name, length); + ud->field_hash = rcheevos_djb2(name, length); if (ud->field_hash == CHEEVOS_JSON_KEY_ACHIEVEMENTS) ud->in_cheevos = 1; @@ -190,10 +190,10 @@ static int cheevos_count_key(void* userdata, return 0; } -static int cheevos_count_number(void* userdata, +static int rcheevos_count_number(void* userdata, const char* number, size_t length) { - cheevos_countud_t* ud = (cheevos_countud_t*)userdata; + rcheevos_countud_t* ud = (rcheevos_countud_t*)userdata; if (ud->in_cheevos && ud->field_hash == CHEEVOS_JSON_KEY_FLAGS) { @@ -210,7 +210,7 @@ static int cheevos_count_number(void* userdata, return 0; } -static int cheevos_count_cheevos(const char* json, +static int rcheevos_count_cheevos(const char* json, unsigned* core_count, unsigned* unofficial_count, unsigned* lboard_count) { @@ -221,17 +221,17 @@ static int cheevos_count_cheevos(const char* json, NULL, NULL, NULL, - cheevos_count_end_array, - cheevos_count_key, + rcheevos_count_end_array, + rcheevos_count_key, NULL, NULL, - cheevos_count_number, + rcheevos_count_number, NULL, NULL }; int res; - cheevos_countud_t ud; + rcheevos_countud_t ud; ud.in_cheevos = 0; ud.in_lboards = 0; ud.core_count = 0; @@ -255,7 +255,7 @@ typedef struct { const char* string; size_t length; -} cheevos_field_t; +} rcheevos_field_t; typedef struct { @@ -266,14 +266,14 @@ typedef struct unsigned unofficial_count; unsigned lboard_count; - cheevos_field_t* field; - cheevos_field_t id, memaddr, title, desc, points, author; - cheevos_field_t modified, created, badge, flags, format; + rcheevos_field_t* field; + rcheevos_field_t id, memaddr, title, desc, points, author; + rcheevos_field_t modified, created, badge, flags, format; - cheevos_rapatchdata_t* patchdata; -} cheevos_readud_t; + rcheevos_rapatchdata_t* patchdata; +} rcheevos_readud_t; -static const char* cheevos_dupstr(const cheevos_field_t* field) +static const char* rcheevos_dupstr(const rcheevos_field_t* field) { char* string = (char*)malloc(field->length + 1); @@ -285,9 +285,9 @@ static const char* cheevos_dupstr(const cheevos_field_t* field) return string; } -static int cheevos_new_cheevo(cheevos_readud_t* ud) +static int rcheevos_new_cheevo(rcheevos_readud_t* ud) { - cheevos_racheevo_t* cheevo = NULL; + rcheevos_racheevo_t* cheevo = NULL; unsigned flags = (unsigned)strtol(ud->flags.string, NULL, 10); if (flags == 3) @@ -297,10 +297,10 @@ static int cheevos_new_cheevo(cheevos_readud_t* ud) else return 0; - cheevo->title = cheevos_dupstr(&ud->title); - cheevo->description = cheevos_dupstr(&ud->desc); - cheevo->badge = cheevos_dupstr(&ud->badge); - cheevo->memaddr = cheevos_dupstr(&ud->memaddr); + cheevo->title = rcheevos_dupstr(&ud->title); + cheevo->description = rcheevos_dupstr(&ud->desc); + cheevo->badge = rcheevos_dupstr(&ud->badge); + cheevo->memaddr = rcheevos_dupstr(&ud->memaddr); cheevo->points = (unsigned)strtol(ud->points.string, NULL, 10); cheevo->id = (unsigned)strtol(ud->id.string, NULL, 10); @@ -319,14 +319,14 @@ static int cheevos_new_cheevo(cheevos_readud_t* ud) return 0; } -static int cheevos_new_lboard(cheevos_readud_t* ud) +static int rcheevos_new_lboard(rcheevos_readud_t* ud) { - cheevos_ralboard_t* lboard = ud->patchdata->lboards + ud->lboard_count++; + rcheevos_ralboard_t* lboard = ud->patchdata->lboards + ud->lboard_count++; - lboard->title = cheevos_dupstr(&ud->title); - lboard->description = cheevos_dupstr(&ud->desc); - lboard->format = cheevos_dupstr(&ud->format); - lboard->mem = cheevos_dupstr(&ud->memaddr); + lboard->title = rcheevos_dupstr(&ud->title); + lboard->description = rcheevos_dupstr(&ud->desc); + lboard->format = rcheevos_dupstr(&ud->format); + lboard->mem = rcheevos_dupstr(&ud->memaddr); lboard->id = (unsigned)strtol(ud->id.string, NULL, 10); if ( !lboard->title @@ -344,35 +344,35 @@ static int cheevos_new_lboard(cheevos_readud_t* ud) return 0; } -static int cheevos_read_end_object(void* userdata) +static int rcheevos_read_end_object(void* userdata) { - cheevos_readud_t* ud = (cheevos_readud_t*)userdata; + rcheevos_readud_t* ud = (rcheevos_readud_t*)userdata; if (ud->in_cheevos) - return cheevos_new_cheevo(ud); + return rcheevos_new_cheevo(ud); if (ud->in_lboards) - return cheevos_new_lboard(ud); + return rcheevos_new_lboard(ud); return 0; } -static int cheevos_read_end_array(void* userdata) +static int rcheevos_read_end_array(void* userdata) { - cheevos_readud_t* ud = (cheevos_readud_t*)userdata; + rcheevos_readud_t* ud = (rcheevos_readud_t*)userdata; ud->in_cheevos = 0; ud->in_lboards = 0; return 0; } -static int cheevos_read_key(void* userdata, +static int rcheevos_read_key(void* userdata, const char* name, size_t length) { - cheevos_readud_t* ud = (cheevos_readud_t*)userdata; + rcheevos_readud_t* ud = (rcheevos_readud_t*)userdata; int common = ud->in_cheevos || ud->in_lboards; - uint32_t hash = cheevos_djb2(name, length); + uint32_t hash = rcheevos_djb2(name, length); ud->field = NULL; switch (hash) @@ -441,10 +441,10 @@ static int cheevos_read_key(void* userdata, return 0; } -static int cheevos_read_string(void* userdata, +static int rcheevos_read_string(void* userdata, const char* string, size_t length) { - cheevos_readud_t* ud = (cheevos_readud_t*)userdata; + rcheevos_readud_t* ud = (rcheevos_readud_t*)userdata; if (ud->field) { @@ -455,10 +455,10 @@ static int cheevos_read_string(void* userdata, return 0; } -static int cheevos_read_number(void* userdata, +static int rcheevos_read_number(void* userdata, const char* number, size_t length) { - cheevos_readud_t* ud = (cheevos_readud_t*)userdata; + rcheevos_readud_t* ud = (rcheevos_readud_t*)userdata; if (ud->field) { @@ -474,29 +474,29 @@ static int cheevos_read_number(void* userdata, return 0; } -int cheevos_get_patchdata(const char* json, cheevos_rapatchdata_t* patchdata) +int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata) { static const jsonsax_handlers_t handlers = { NULL, NULL, NULL, - cheevos_read_end_object, + rcheevos_read_end_object, NULL, - cheevos_read_end_array, - cheevos_read_key, + rcheevos_read_end_array, + rcheevos_read_key, NULL, - cheevos_read_string, - cheevos_read_number, + rcheevos_read_string, + rcheevos_read_number, NULL, NULL }; - cheevos_readud_t ud; + rcheevos_readud_t ud; int res; /* Count the number of achievements in the JSON file. */ - res = cheevos_count_cheevos(json, &patchdata->core_count, + res = rcheevos_count_cheevos(json, &patchdata->core_count, &patchdata->unofficial_count, &patchdata->lboard_count); if (res != JSONSAX_OK) @@ -504,14 +504,14 @@ int cheevos_get_patchdata(const char* json, cheevos_rapatchdata_t* patchdata) /* Allocate the achievements. */ - patchdata->core = (cheevos_racheevo_t*) - calloc(patchdata->core_count, sizeof(cheevos_racheevo_t)); + patchdata->core = (rcheevos_racheevo_t*) + calloc(patchdata->core_count, sizeof(rcheevos_racheevo_t)); - patchdata->unofficial = (cheevos_racheevo_t*) - calloc(patchdata->unofficial_count, sizeof(cheevos_racheevo_t)); + patchdata->unofficial = (rcheevos_racheevo_t*) + calloc(patchdata->unofficial_count, sizeof(rcheevos_racheevo_t)); - patchdata->lboards = (cheevos_ralboard_t*) - calloc(patchdata->lboard_count, sizeof(cheevos_ralboard_t)); + patchdata->lboards = (rcheevos_ralboard_t*) + calloc(patchdata->lboard_count, sizeof(rcheevos_ralboard_t)); if (!patchdata->core || !patchdata->unofficial || @@ -536,7 +536,7 @@ int cheevos_get_patchdata(const char* json, cheevos_rapatchdata_t* patchdata) if (jsonsax_parse(json, &handlers, (void*)&ud) != JSONSAX_OK) { - cheevos_free_patchdata(patchdata); + rcheevos_free_patchdata(patchdata); return -1; } @@ -547,11 +547,11 @@ int cheevos_get_patchdata(const char* json, cheevos_rapatchdata_t* patchdata) Frees the patchdata *****************************************************************************/ -void cheevos_free_patchdata(cheevos_rapatchdata_t* patchdata) +void rcheevos_free_patchdata(rcheevos_rapatchdata_t* patchdata) { unsigned i = 0, count = 0; - const cheevos_racheevo_t* cheevo = NULL; - const cheevos_ralboard_t* lboard = NULL; + const rcheevos_racheevo_t* cheevo = NULL; + const rcheevos_ralboard_t* lboard = NULL; cheevo = patchdata->core; @@ -603,22 +603,22 @@ Deactivates unlocked cheevos typedef struct { int is_element; - cheevos_unlock_cb_t unlock_cb; + rcheevos_unlock_cb_t unlock_cb; void* userdata; -} cheevos_deactivate_t; +} rcheevos_deactivate_t; -static int cheevos_deactivate_index(void* userdata, unsigned int index) +static int rcheevos_deactivate_index(void* userdata, unsigned int index) { - cheevos_deactivate_t* ud = (cheevos_deactivate_t*)userdata; + rcheevos_deactivate_t* ud = (rcheevos_deactivate_t*)userdata; ud->is_element = 1; return 0; } -static int cheevos_deactivate_number(void* userdata, +static int rcheevos_deactivate_number(void* userdata, const char* number, size_t length) { - cheevos_deactivate_t* ud = (cheevos_deactivate_t*)userdata; + rcheevos_deactivate_t* ud = (rcheevos_deactivate_t*)userdata; unsigned id = 0; if (ud->is_element) @@ -632,7 +632,7 @@ static int cheevos_deactivate_number(void* userdata, return 0; } -void cheevos_deactivate_unlocks(const char* json, cheevos_unlock_cb_t unlock_cb, void* userdata) +void rcheevos_deactivate_unlocks(const char* json, rcheevos_unlock_cb_t unlock_cb, void* userdata) { static const jsonsax_handlers_t handlers = { @@ -643,14 +643,14 @@ void cheevos_deactivate_unlocks(const char* json, cheevos_unlock_cb_t unlock_cb, NULL, NULL, NULL, - cheevos_deactivate_index, + rcheevos_deactivate_index, NULL, - cheevos_deactivate_number, + rcheevos_deactivate_number, NULL, NULL }; - cheevos_deactivate_t ud; + rcheevos_deactivate_t ud; ud.is_element = 0; ud.unlock_cb = unlock_cb; @@ -667,7 +667,7 @@ unsigned chevos_get_gameid(const char* json) { char gameid[32]; - if (cheevos_get_value(json, CHEEVOS_JSON_KEY_GAMEID, gameid, sizeof(gameid)) != 0) + if (rcheevos_get_value(json, CHEEVOS_JSON_KEY_GAMEID, gameid, sizeof(gameid)) != 0) return 0; return (unsigned)strtol(gameid, NULL, 10); diff --git a/cheevos-new/parser.h b/cheevos-new/parser.h index 5b10de6236..b9706f5474 100644 --- a/cheevos-new/parser.h +++ b/cheevos-new/parser.h @@ -31,7 +31,7 @@ typedef struct { const char* memaddr; unsigned points; unsigned id; -} cheevos_racheevo_t; +} rcheevos_racheevo_t; typedef struct { const char* title; @@ -39,28 +39,28 @@ typedef struct { const char* format; const char* mem; unsigned id; -} cheevos_ralboard_t; +} rcheevos_ralboard_t; typedef struct { unsigned console_id; - cheevos_racheevo_t* core; - cheevos_racheevo_t* unofficial; - cheevos_ralboard_t* lboards; + rcheevos_racheevo_t* core; + rcheevos_racheevo_t* unofficial; + rcheevos_ralboard_t* lboards; unsigned core_count; unsigned unofficial_count; unsigned lboard_count; -} cheevos_rapatchdata_t; +} rcheevos_rapatchdata_t; -typedef void (*cheevos_unlock_cb_t)(unsigned id, void* userdata); +typedef void (*rcheevos_unlock_cb_t)(unsigned id, void* userdata); -int cheevos_get_token(const char* json, char* token, size_t length); +int rcheevos_get_token(const char* json, char* token, size_t length); -int cheevos_get_patchdata(const char* json, cheevos_rapatchdata_t* patchdata); -void cheevos_free_patchdata(cheevos_rapatchdata_t* patchdata); +int rcheevos_get_patchdata(const char* json, rcheevos_rapatchdata_t* patchdata); +void rcheevos_free_patchdata(rcheevos_rapatchdata_t* patchdata); -void cheevos_deactivate_unlocks(const char* json, cheevos_unlock_cb_t unlock_cb, void* userdata); +void rcheevos_deactivate_unlocks(const char* json, rcheevos_unlock_cb_t unlock_cb, void* userdata); unsigned chevos_get_gameid(const char* json); diff --git a/cheevos-new/util.h b/cheevos-new/util.h index 4e389cf404..1794ef3ebb 100644 --- a/cheevos-new/util.h +++ b/cheevos-new/util.h @@ -25,13 +25,13 @@ Setup - mainly for debugging *****************************************************************************/ /* Define this macro to get extra-verbose log for cheevos. */ -#undef CHEEVOS_VERBOSE +#define CHEEVOS_VERBOSE /***************************************************************************** End of setup *****************************************************************************/ -#define CHEEVOS_TAG "[CHEEVOS]: " +#define RCHEEVOS_TAG "[RCHEEVOS]: " #define CHEEVOS_FREE(p) do { void* q = (void*)p; if (q != NULL) free(q); } while (0) #ifdef CHEEVOS_VERBOSE @@ -41,10 +41,10 @@ End of setup #else -#define CHEEVOS_LOG cheevos_log +#define CHEEVOS_LOG rcheevos_log #define CHEEVOS_ERR RARCH_ERR -void cheevos_log(const char *fmt, ...); +void rcheevos_log(const char *fmt, ...); #endif diff --git a/cheevos/badges.h b/cheevos/badges.h index c8788306c0..59a5737101 100644 --- a/cheevos/badges.h +++ b/cheevos/badges.h @@ -16,10 +16,6 @@ #ifndef __RARCH_CHEEVOS_OLD_BADGE_H #define __RARCH_CHEEVOS_OLD_BADGE_H -#ifdef HAVE_NEW_CHEEVOS -#include "../cheevos-new/badges.h" -#else - #include "../menu/menu_driver.h" #include @@ -46,5 +42,3 @@ static badges_ctx_t new_badges_ctx; RETRO_END_DECLS #endif - -#endif diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 8dd2b2c995..251475a52c 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -1862,8 +1862,6 @@ static void cheevos_test_leaderboards(void) if (value != lboard->last_value) { - CHEEVOS_LOG("[CHEEVOS]: value lboard %s %u\n", - lboard->title, value); lboard->last_value = value; } diff --git a/cheevos/cheevos.h b/cheevos/cheevos.h index c65c2afbc9..3855bef73d 100644 --- a/cheevos/cheevos.h +++ b/cheevos/cheevos.h @@ -16,10 +16,6 @@ #ifndef __RARCH_CHEEVOS_OLD_H #define __RARCH_CHEEVOS_OLD_H -#ifdef HAVE_NEW_CHEEVOS -#include "../cheevos-new/cheevos.h" -#else - #include #include @@ -34,7 +30,7 @@ Setup - mainly for debugging *****************************************************************************/ /* Define this macro to get extra-verbose log for cheevos. */ -#undef CHEEVOS_VERBOSE +#define CHEEVOS_VERBOSE /***************************************************************************** End of setup @@ -166,6 +162,4 @@ extern int cheats_were_enabled; RETRO_END_DECLS -#endif - #endif /* __RARCH_CHEEVOS_H */ diff --git a/command.c b/command.c index 85a07db7e9..a1efc824fd 100755 --- a/command.c +++ b/command.c @@ -41,11 +41,9 @@ #ifdef HAVE_CHEEVOS #include "cheevos/cheevos.h" -#ifdef HAVE_NEW_CHEEVOS -#include "cheevos-new/fixup.h" -#else #include "cheevos/var.h" -#endif +#include "cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove lines */ +#include "cheevos-new/fixup.h" #endif #ifdef HAVE_DISCORD @@ -279,9 +277,10 @@ bool command_set_shader(const char *arg) #define SMY_CMD_STR "READ_CORE_RAM" static bool command_read_ram(const char *arg) { -#if !defined(HAVE_NEW_CHEEVOS) + /* RCHEEVOS TODO: remove settings init and test */ + settings_t *settings = config_get_ptr(); cheevos_var_t var; -#endif + unsigned i; char *reply = NULL; const uint8_t *data = NULL; @@ -297,13 +296,18 @@ static bool command_read_ram(const char *arg) reply[0] = '\0'; reply_at = reply + snprintf(reply, alloc_size - 1, SMY_CMD_STR " %x", addr); -#if defined(HAVE_NEW_CHEEVOS) - data = cheevos_patch_address(addr, cheevos_get_console()); -#else - var.value = addr; - cheevos_var_patch_addr(&var, cheevos_get_console()); - data = cheevos_var_get_memory(&var); -#endif + /* RCHEEVOS TODO: remove if condition below */ + if (settings->bools.cheevos_rcheevos_enable) + { + data = rcheevos_patch_address(addr, rcheevos_get_console()); + } + /* RCHEEVOS TODO: remove whole else block below */ + else + { + var.value = addr; + cheevos_var_patch_addr(&var, cheevos_get_console()); + data = cheevos_var_get_memory(&var); + } if (data) { @@ -324,19 +328,28 @@ static bool command_read_ram(const char *arg) static bool command_write_ram(const char *arg) { - unsigned nbytes = 0; -#if defined(HAVE_NEW_CHEEVOS) - unsigned int addr = strtoul(arg, (char**)&arg, 16); - uint8_t *data = (uint8_t *)cheevos_patch_address(addr, cheevos_get_console()); -#else - cheevos_var_t var; - uint8_t *data = NULL; + unsigned nbytes = 0; + uint8_t *data = NULL; + unsigned int addr = 0; - var.value = strtoul(arg, (char**)&arg, 16); - cheevos_var_patch_addr(&var, cheevos_get_console()); + /* RCHEEVOS TODO: remove settings init and test */ + settings_t *settings = config_get_ptr(); - data = cheevos_var_get_memory(&var); -#endif + if (settings->bools.cheevos_rcheevos_enable) + { + addr = strtoul(arg, (char**)&arg, 16); + data = (uint8_t *)rcheevos_patch_address(addr, rcheevos_get_console()); + } + /* RCHEEVOS TODO: remove the whole else block below */ + else + { + cheevos_var_t var; + + var.value = strtoul(arg, (char**)&arg, 16); + cheevos_var_patch_addr(&var, cheevos_get_console()); + + data = cheevos_var_get_memory(&var); + } if (data) { @@ -1095,7 +1108,9 @@ static void command_event_init_controllers(void) static void command_event_deinit_core(bool reinit) { #ifdef HAVE_CHEEVOS - cheevos_unload(); + /* RCHEEVOS TODO: remove settings init and test */ + settings_t *settings = config_get_ptr(); + settings->bools.cheevos_rcheevos_enable ? rcheevos_unload() : cheevos_unload(); #endif RARCH_LOG("Unloading game..\n"); @@ -1150,7 +1165,8 @@ static void command_event_load_auto_state(void) #endif #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) goto error; #endif @@ -1401,7 +1417,8 @@ static bool command_event_save_auto_state(void) goto error; #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) goto error; #endif @@ -1701,7 +1718,8 @@ static bool command_event_main_state(unsigned cmd) if (content_load_state(state_path, false, false)) { #ifdef HAVE_CHEEVOS - cheevos_state_loaded_flag = true; + /* RCHEEVOS TODO: remove duplication below */ + rcheevos_state_loaded_flag = cheevos_state_loaded_flag = true; #endif ret = true; #ifdef HAVE_NETWORKING @@ -1848,7 +1866,8 @@ bool command_event(enum event_command cmd, void *data) return false; #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) return false; #endif if (!command_event_main_state(cmd)) @@ -1878,29 +1897,34 @@ bool command_event(enum event_command cmd, void *data) command_event_init_controllers(); break; case CMD_EVENT_RESET: + /* RCHEEVOS TODO: remove starting block bracket, settings init and tests */ + { #ifdef HAVE_CHEEVOS - cheevos_state_loaded_flag = false; - cheevos_hardcore_paused = false; + settings_t *settings = config_get_ptr(); + rcheevos_state_loaded_flag = cheevos_state_loaded_flag = false; + rcheevos_hardcore_paused = cheevos_hardcore_paused = false; #endif - RARCH_LOG("%s.\n", msg_hash_to_str(MSG_RESET)); - runloop_msg_queue_push(msg_hash_to_str(MSG_RESET), 1, 120, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); + RARCH_LOG("%s.\n", msg_hash_to_str(MSG_RESET)); + runloop_msg_queue_push(msg_hash_to_str(MSG_RESET), 1, 120, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); #ifdef HAVE_CHEEVOS - cheevos_set_cheats(); + settings->bools.cheevos_rcheevos_enable ? rcheevos_set_cheats() : cheevos_set_cheats(); #endif - core_reset(); + core_reset(); #ifdef HAVE_CHEEVOS - cheevos_reset_game(); + settings->bools.cheevos_rcheevos_enable ? rcheevos_reset_game() : cheevos_reset_game(); #endif #if HAVE_NETWORKING - netplay_driver_ctl(RARCH_NETPLAY_CTL_RESET, NULL); + netplay_driver_ctl(RARCH_NETPLAY_CTL_RESET, NULL); #endif - return false; + return false; + } case CMD_EVENT_SAVE_STATE: { settings_t *settings = config_get_ptr(); #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) return false; #endif @@ -1982,7 +2006,11 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_CHEEVOS_HARDCORE_MODE_TOGGLE: #ifdef HAVE_CHEEVOS - cheevos_toggle_hardcore_mode(); + /* RCHEEVOS TODO: remove starting block bracket, settings init and test */ + { + settings_t *settings = config_get_ptr(); + settings->bools.cheevos_rcheevos_enable ? rcheevos_toggle_hardcore_mode() : cheevos_toggle_hardcore_mode(); + } #endif break; /* this fallthrough is on purpose, it should do @@ -2023,7 +2051,8 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_REWIND_DEINIT: #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) return false; #endif state_manager_event_deinit(); @@ -2032,7 +2061,8 @@ bool command_event(enum event_command cmd, void *data) { settings_t *settings = config_get_ptr(); #ifdef HAVE_CHEEVOS - if (cheevos_hardcore_active) + /* RCHEEVOS TODO: remove OR below */ + if (cheevos_hardcore_active || rcheevos_hardcore_active) return false; #endif if (settings->bools.rewind_enable) diff --git a/configuration.c b/configuration.c index 0299c28002..1ddbf297fe 100644 --- a/configuration.c +++ b/configuration.c @@ -1526,6 +1526,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("cheevos_leaderboards_enable", &settings->bools.cheevos_leaderboards_enable, true, false, false); SETTING_BOOL("cheevos_verbose_enable", &settings->bools.cheevos_verbose_enable, true, false, false); SETTING_BOOL("cheevos_auto_screenshot", &settings->bools.cheevos_auto_screenshot, true, false, false); + SETTING_BOOL("cheevos_rcheevos_enable", &settings->bools.cheevos_rcheevos_enable, true, false, false); + /* RCHEEVOS TODO: remove line above */ #ifdef HAVE_XMB SETTING_BOOL("cheevos_badges_enable", &settings->bools.cheevos_badges_enable, true, false, false); #endif diff --git a/configuration.h b/configuration.h index eb1a185b0e..fee6d81663 100644 --- a/configuration.h +++ b/configuration.h @@ -240,6 +240,7 @@ typedef struct settings bool cheevos_badges_enable; bool cheevos_verbose_enable; bool cheevos_auto_screenshot; + bool cheevos_rcheevos_enable; /* RCHEEVOS TODO: remove line */ /* Camera */ bool camera_allow; diff --git a/deps/rcheevos/include/rcheevos.h b/deps/rcheevos/include/rcheevos.h index 4ccf3c623d..c15f72596e 100644 --- a/deps/rcheevos/include/rcheevos.h +++ b/deps/rcheevos/include/rcheevos.h @@ -29,7 +29,9 @@ enum { RC_MISSING_CANCEL = -14, RC_MISSING_SUBMIT = -15, RC_MISSING_VALUE = -16, - RC_INVALID_LBOARD_FIELD = -17 + RC_INVALID_LBOARD_FIELD = -17, + RC_MISSING_DISPLAY_STRING = -18, + RC_OUT_OF_MEMORY = -19 }; /*****************************************************************************\ @@ -82,51 +84,74 @@ enum { typedef unsigned (*rc_peek_t)(unsigned address, unsigned num_bytes, void* ud); /*****************************************************************************\ -| Operands | +| Memory References | \*****************************************************************************/ /* Sizes. */ enum { - RC_OPERAND_BIT_0, - RC_OPERAND_BIT_1, - RC_OPERAND_BIT_2, - RC_OPERAND_BIT_3, - RC_OPERAND_BIT_4, - RC_OPERAND_BIT_5, - RC_OPERAND_BIT_6, - RC_OPERAND_BIT_7, - RC_OPERAND_LOW, - RC_OPERAND_HIGH, - RC_OPERAND_8_BITS, - RC_OPERAND_16_BITS, - RC_OPERAND_24_BITS, - RC_OPERAND_32_BITS + RC_MEMSIZE_BIT_0, + RC_MEMSIZE_BIT_1, + RC_MEMSIZE_BIT_2, + RC_MEMSIZE_BIT_3, + RC_MEMSIZE_BIT_4, + RC_MEMSIZE_BIT_5, + RC_MEMSIZE_BIT_6, + RC_MEMSIZE_BIT_7, + RC_MEMSIZE_LOW, + RC_MEMSIZE_HIGH, + RC_MEMSIZE_8_BITS, + RC_MEMSIZE_16_BITS, + RC_MEMSIZE_24_BITS, + RC_MEMSIZE_32_BITS }; +typedef struct { + /* The memory address of this variable. */ + unsigned address; + /* The size of the variable. */ + char size; + /* True if the value is in BCD. */ + char is_bcd; +} rc_memref_t; + +typedef struct rc_memref_value_t rc_memref_value_t; + +struct rc_memref_value_t { + /* The value of this memory reference. */ + unsigned value; + /* The previous value of this memory reference. */ + unsigned previous; + /* The last differing value of this memory reference. */ + unsigned prior; + + /* The referenced memory */ + rc_memref_t memref; + + /* The next memory reference in the chain */ + rc_memref_value_t* next; +}; + +/*****************************************************************************\ +| Operands | +\*****************************************************************************/ + /* types */ enum { RC_OPERAND_ADDRESS, /* Compare to the value of a live address in RAM. */ RC_OPERAND_DELTA, /* The value last known at this address. */ RC_OPERAND_CONST, /* A 32-bit unsigned integer. */ RC_OPERAND_FP, /* A floating point value. */ - RC_OPERAND_LUA /* A Lua function that provides the value. */ + RC_OPERAND_LUA, /* A Lua function that provides the value. */ + RC_OPERAND_PRIOR /* The last differing value at this address. */ }; typedef struct { union { /* A value read from memory. */ - struct { - /* The memory address or constant value of this variable. */ - unsigned value; - /* The previous memory contents if RC_OPERAND_DELTA. */ - unsigned previous; + rc_memref_value_t* memref; - /* The size of the variable. */ - char size; - /* True if the value is in BCD. */ - char is_bcd; - /* The type of the variable. */ - }; + /* A value. */ + unsigned value; /* A floating point value. */ double fp_value; @@ -150,7 +175,8 @@ enum { RC_CONDITION_RESET_IF, RC_CONDITION_ADD_SOURCE, RC_CONDITION_SUB_SOURCE, - RC_CONDITION_ADD_HITS + RC_CONDITION_ADD_HITS, + RC_CONDITION_AND_NEXT }; /* operators */ @@ -166,9 +192,6 @@ enum { typedef struct rc_condition_t rc_condition_t; struct rc_condition_t { - /* The next condition in the chain. */ - rc_condition_t* next; - /* The condition's operands. */ rc_operand_t operand1; rc_operand_t operand2; @@ -178,6 +201,9 @@ struct rc_condition_t { /* Number of hits so far. */ unsigned current_hits; + /* The next condition in the chain. */ + rc_condition_t* next; + /** * Set if the condition needs to processed as part of the "check if paused" * pass @@ -217,6 +243,9 @@ typedef struct { /* The list of sub condition sets in this test. */ rc_condset_t* alternative; + + /* The memory references required by the trigger. */ + rc_memref_value_t* memrefs; } rc_trigger_t; @@ -257,6 +286,9 @@ struct rc_expression_t { typedef struct { /* The list of expression to evaluate. */ rc_expression_t* expressions; + + /* The memory references required by the value. */ + rc_memref_value_t* memrefs; } rc_value_t; @@ -283,6 +315,7 @@ typedef struct { rc_trigger_t cancel; rc_value_t value; rc_value_t* progress; + rc_memref_value_t* memrefs; char started; char submitted; @@ -300,7 +333,7 @@ void rc_reset_lboard(rc_lboard_t* lboard); /* Supported formats. */ enum { - RC_FORMAT_FRAMES = 0, + RC_FORMAT_FRAMES, RC_FORMAT_SECONDS, RC_FORMAT_CENTISECS, RC_FORMAT_SCORE, @@ -309,7 +342,57 @@ enum { }; int rc_parse_format(const char* format_str); -void rc_format_value(char* buffer, int size, unsigned value, int format); +int rc_format_value(char* buffer, int size, unsigned value, int format); + +/*****************************************************************************\ +| Rich Presence | +\*****************************************************************************/ + +typedef struct rc_richpresence_lookup_item_t rc_richpresence_lookup_item_t; + +struct rc_richpresence_lookup_item_t { + unsigned value; + rc_richpresence_lookup_item_t* next_item; + const char* label; +}; + +typedef struct rc_richpresence_lookup_t rc_richpresence_lookup_t; + +struct rc_richpresence_lookup_t { + rc_richpresence_lookup_item_t* first_item; + rc_richpresence_lookup_t* next; + const char* name; + unsigned short format; +}; + +typedef struct rc_richpresence_display_part_t rc_richpresence_display_part_t; + +struct rc_richpresence_display_part_t { + rc_richpresence_display_part_t* next; + const char* text; + rc_richpresence_lookup_item_t* first_lookup_item; + rc_value_t value; + unsigned short display_type; +}; + +typedef struct rc_richpresence_display_t rc_richpresence_display_t; + +struct rc_richpresence_display_t { + rc_trigger_t trigger; + rc_richpresence_display_t* next; + rc_richpresence_display_part_t* display; +}; + +typedef struct { + rc_richpresence_display_t* first_display; + rc_richpresence_lookup_t* first_lookup; + rc_memref_value_t* memrefs; +} +rc_richpresence_t; + +int rc_richpresence_size(const char* script); +rc_richpresence_t* rc_parse_richpresence(void* buffer, const char* script, lua_State* L, int funcs_ndx); +int rc_evaluate_richpresence(rc_richpresence_t* richpresence, char* buffer, unsigned buffersize, rc_peek_t peek, void* peek_ud, lua_State* L); #ifdef __cplusplus } diff --git a/deps/rcheevos/src/rcheevos/alloc.c b/deps/rcheevos/src/rcheevos/alloc.c index fb573666b9..83b9ec71ef 100644 --- a/deps/rcheevos/src/rcheevos/alloc.c +++ b/deps/rcheevos/src/rcheevos/alloc.c @@ -1,5 +1,8 @@ #include "internal.h" +#include +#include + void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t* scratch) { void* ptr; @@ -8,10 +11,43 @@ void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t if (pointer != 0) { ptr = (void*)((char*)pointer + *offset); } + else if (scratch != 0) { + ptr = &scratch->obj; + } else { - ptr = scratch; + ptr = 0; } *offset += size; return ptr; } + +char* rc_alloc_str(rc_parse_state_t* parse, const char* text, int length) { + char* ptr; + + ptr = (char*)rc_alloc(parse->buffer, &parse->offset, length + 1, RC_ALIGNOF(char), 0); + if (ptr) { + memcpy(ptr, text, length); + ptr[length] = '\0'; + } + + return ptr; +} + +void rc_init_parse_state(rc_parse_state_t* parse, void* buffer, lua_State* L, int funcs_ndx) +{ + parse->offset = 0; + parse->L = L; + parse->funcs_ndx = funcs_ndx; + parse->buffer = buffer; + parse->scratch.memref = parse->scratch.memref_buffer; + parse->scratch.memref_size = sizeof(parse->scratch.memref_buffer) / sizeof(parse->scratch.memref_buffer[0]); + parse->scratch.memref_count = 0; + parse->first_memref = 0; +} + +void rc_destroy_parse_state(rc_parse_state_t* parse) +{ + if (parse->scratch.memref != parse->scratch.memref_buffer) + free(parse->scratch.memref); +} \ No newline at end of file diff --git a/deps/rcheevos/src/rcheevos/condition.c b/deps/rcheevos/src/rcheevos/condition.c index f6f17204eb..efd172a6d2 100644 --- a/deps/rcheevos/src/rcheevos/condition.c +++ b/deps/rcheevos/src/rcheevos/condition.c @@ -2,13 +2,13 @@ #include -rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +rc_condition_t* rc_parse_condition(const char** memaddr, rc_parse_state_t* parse) { rc_condition_t* self; const char* aux; int ret2; aux = *memaddr; - self = RC_ALLOC(rc_condition_t, buffer, ret, scratch); + self = RC_ALLOC(rc_condition_t, parse); self->current_hits = 0; if (*aux != 0 && aux[1] == ':') { @@ -18,7 +18,8 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch case 'a': case 'A': self->type = RC_CONDITION_ADD_SOURCE; break; case 'b': case 'B': self->type = RC_CONDITION_SUB_SOURCE; break; case 'c': case 'C': self->type = RC_CONDITION_ADD_HITS; break; - default: *ret = RC_INVALID_CONDITION_TYPE; return 0; + case 'n': case 'N': self->type = RC_CONDITION_AND_NEXT; break; + default: parse->offset = RC_INVALID_CONDITION_TYPE; return 0; } aux += 2; @@ -27,10 +28,10 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch self->type = RC_CONDITION_STANDARD; } - ret2 = rc_parse_operand(&self->operand1, &aux, 1, L, funcs_ndx); + ret2 = rc_parse_operand(&self->operand1, &aux, 1, parse); if (ret2 < 0) { - *ret = ret2; + parse->offset = ret2; return 0; } @@ -44,7 +45,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch if (*aux++ != '=') { /* fall through */ default: - *ret = RC_INVALID_OPERATOR; + parse->offset = RC_INVALID_OPERATOR; return 0; } @@ -72,10 +73,10 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch break; } - ret2 = rc_parse_operand(&self->operand2, &aux, 1, L, funcs_ndx); + ret2 = rc_parse_operand(&self->operand2, &aux, 1, parse); if (ret2 < 0) { - *ret = ret2; + parse->offset = ret2; return 0; } @@ -84,7 +85,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch self->required_hits = (unsigned)strtoul(++aux, &end, 10); if (end == aux || *end != ')') { - *ret = RC_INVALID_REQUIRED_HITS; + parse->offset = RC_INVALID_REQUIRED_HITS; return 0; } @@ -95,7 +96,7 @@ rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch self->required_hits = (unsigned)strtoul(++aux, &end, 10); if (end == aux || *end != '.') { - *ret = RC_INVALID_REQUIRED_HITS; + parse->offset = RC_INVALID_REQUIRED_HITS; return 0; } diff --git a/deps/rcheevos/src/rcheevos/condset.c b/deps/rcheevos/src/rcheevos/condset.c index 5062bd1490..c2d59a2691 100644 --- a/deps/rcheevos/src/rcheevos/condset.c +++ b/deps/rcheevos/src/rcheevos/condset.c @@ -13,6 +13,7 @@ static void rc_update_condition_pause(rc_condition_t* condition, int* in_pause) case RC_CONDITION_ADD_SOURCE: case RC_CONDITION_SUB_SOURCE: case RC_CONDITION_ADD_HITS: + case RC_CONDITION_AND_NEXT: condition->pause = *in_pause; break; @@ -22,19 +23,25 @@ static void rc_update_condition_pause(rc_condition_t* condition, int* in_pause) } } -rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +rc_condset_t* rc_parse_condset(const char** memaddr, rc_parse_state_t* parse) { rc_condset_t* self; rc_condition_t** next; int in_pause; - self = RC_ALLOC(rc_condset_t, buffer, ret, scratch); + self = RC_ALLOC(rc_condset_t, parse); self->has_pause = 0; next = &self->conditions; - for (;;) { - *next = rc_parse_condition(ret, buffer, scratch, memaddr, L, funcs_ndx); + if (**memaddr == 'S' || **memaddr == 's' || !**memaddr) { + /* empty group - editor allows it, so we have to support it */ + *next = 0; + return self; + } - if (*ret < 0) { + for (;;) { + *next = rc_parse_condition(memaddr, parse); + + if (parse->offset < 0) { return 0; } @@ -51,7 +58,7 @@ rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, co *next = 0; - if (buffer != 0) { + if (parse->buffer != 0) { in_pause = 0; rc_update_condition_pause(self->conditions, &in_pause); } @@ -61,10 +68,11 @@ rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, co static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, int* reset, rc_peek_t peek, void* ud, lua_State* L) { rc_condition_t* condition; - int set_valid, cond_valid; + int set_valid, cond_valid, prev_cond; unsigned add_buffer, add_hits; set_valid = 1; + prev_cond = 1; add_buffer = add_hits = 0; for (condition = self->conditions; condition != 0; condition = condition->next) { @@ -88,13 +96,23 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, in } } + add_buffer = 0; add_hits += condition->current_hits; continue; + + case RC_CONDITION_AND_NEXT: + prev_cond &= rc_test_condition(condition, add_buffer, peek, ud, L); + add_buffer = 0; + continue; } /* always evaluate the condition to ensure delta values get tracked correctly */ cond_valid = rc_test_condition(condition, add_buffer, peek, ud, L); + /* merge AndNext value and reset it for the next condition */ + cond_valid &= prev_cond; + prev_cond = 1; + /* if the condition has a target hit count that has already been met, it's automatically true, even if not currently true. */ if (condition->required_hits != 0 && (condition->current_hits + add_hits) >= condition->required_hits) { cond_valid = 1; @@ -111,6 +129,7 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, in } } + /* reset AddHits and AddSource/SubSource values */ add_buffer = add_hits = 0; switch (condition->type) { @@ -141,7 +160,7 @@ static int rc_test_condset_internal(rc_condset_t* self, int processing_pause, in } break; - + default: set_valid &= cond_valid; break; diff --git a/deps/rcheevos/src/rcheevos/expression.c b/deps/rcheevos/src/rcheevos/expression.c index 87e458741a..f2fca1e863 100644 --- a/deps/rcheevos/src/rcheevos/expression.c +++ b/deps/rcheevos/src/rcheevos/expression.c @@ -1,16 +1,16 @@ #include "internal.h" -rc_expression_t* rc_parse_expression(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +rc_expression_t* rc_parse_expression(const char** memaddr, rc_parse_state_t* parse) { rc_expression_t* self; rc_term_t** next; - self = RC_ALLOC(rc_expression_t, buffer, ret, scratch); + self = RC_ALLOC(rc_expression_t, parse); next = &self->terms; for (;;) { - *next = rc_parse_term(ret, buffer, scratch, memaddr, L, funcs_ndx); + *next = rc_parse_term(memaddr, parse); - if (*ret < 0) { + if (parse->offset < 0) { return 0; } diff --git a/deps/rcheevos/src/rcheevos/format.c b/deps/rcheevos/src/rcheevos/format.c index e9084064c2..e03ced8070 100644 --- a/deps/rcheevos/src/rcheevos/format.c +++ b/deps/rcheevos/src/rcheevos/format.c @@ -64,8 +64,9 @@ int rc_parse_format(const char* format_str) { return RC_FORMAT_VALUE; } -void rc_format_value(char* buffer, int size, unsigned value, int format) { +int rc_format_value(char* buffer, int size, unsigned value, int format) { unsigned a, b, c; + int chars; switch (format) { case RC_FORMAT_FRAMES: @@ -74,13 +75,13 @@ void rc_format_value(char* buffer, int size, unsigned value, int format) { a -= b * 100; c = b / 60; /* minutes */ b -= c * 60; - snprintf(buffer, size, "%02u:%02u.%02u", c, b, a); + chars = snprintf(buffer, size, "%02u:%02u.%02u", c, b, a); break; case RC_FORMAT_SECONDS: a = value / 60; /* minutes */ value -= a * 60; - snprintf(buffer, size, "%02u:%02u", a, value); + chars = snprintf(buffer, size, "%02u:%02u", a, value); break; case RC_FORMAT_CENTISECS: @@ -88,19 +89,22 @@ void rc_format_value(char* buffer, int size, unsigned value, int format) { value -= a * 100; b = a / 60; /* minutes */ a -= b * 60; - snprintf(buffer, size, "%02u:%02u.%02u", b, a, value); + chars = snprintf(buffer, size, "%02u:%02u.%02u", b, a, value); break; case RC_FORMAT_SCORE: - snprintf(buffer, size, "%06u Points", value); + chars = snprintf(buffer, size, "%06u Points", value); break; case RC_FORMAT_VALUE: - snprintf(buffer, size, "%01u", value); + chars = snprintf(buffer, size, "%01u", value); break; case RC_FORMAT_OTHER: default: - snprintf(buffer, size, "%06u", value); + chars = snprintf(buffer, size, "%06u", value); + break; } + + return chars; } diff --git a/deps/rcheevos/src/rcheevos/internal.h b/deps/rcheevos/src/rcheevos/internal.h index 52a3623105..abdb398371 100644 --- a/deps/rcheevos/src/rcheevos/internal.h +++ b/deps/rcheevos/src/rcheevos/internal.h @@ -3,44 +3,83 @@ #include "rcheevos.h" +#define RC_TAG2(x,y) x ## y +#define RC_TAG(x,y) RC_TAG2(x,y) #define RC_OFFSETOF(s, f) ((int)(long long)(&((s*)0)->f)) -#define RC_ALIGNOF(t) RC_OFFSETOF(struct{char c; t d;}, d) +#define RC_ALIGNOF(t) RC_OFFSETOF(struct RC_TAG(_unnamed, __LINE__) {char c; t d;}, d) -#define RC_ALLOC(t, p, o, s) ((t*)rc_alloc(p, o, sizeof(t), RC_ALIGNOF(t), s)) +#define RC_ALLOC(t, p) ((t*)rc_alloc((p)->buffer, &(p)->offset, sizeof(t), RC_ALIGNOF(t), &(p)->scratch)) -typedef union { - rc_operand_t operand; - rc_condition_t condition; - rc_condset_t condset; - rc_trigger_t trigger; - rc_term_t term; - rc_expression_t expression; - rc_lboard_t lboard; +typedef struct { + rc_memref_t memref_buffer[16]; + rc_memref_t *memref; + int memref_count; + int memref_size; + + union + { + rc_operand_t operand; + rc_condition_t condition; + rc_condset_t condset; + rc_trigger_t trigger; + rc_term_t term; + rc_expression_t expression; + rc_lboard_t lboard; + rc_memref_value_t memref_value; + rc_richpresence_t richpresence; + rc_richpresence_display_t richpresence_display; + rc_richpresence_display_part_t richpresence_part; + rc_richpresence_lookup_t richpresence_lookup; + rc_richpresence_lookup_item_t richpresence_lookup_item; + } obj; } rc_scratch_t; +typedef struct { + int offset; + + lua_State* L; + int funcs_ndx; + + void* buffer; + rc_scratch_t scratch; + + rc_memref_value_t** first_memref; +} +rc_parse_state_t; + +void rc_init_parse_state(rc_parse_state_t* parse, void* buffer, lua_State* L, int funcs_ndx); +void rc_init_parse_state_memrefs(rc_parse_state_t* parse, rc_memref_value_t** memrefs); +void rc_destroy_parse_state(rc_parse_state_t* parse); + void* rc_alloc(void* pointer, int* offset, int size, int alignment, rc_scratch_t* scratch); +char* rc_alloc_str(rc_parse_state_t* parse, const char* text, int length); -void rc_parse_trigger_internal(rc_trigger_t* self, int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +rc_memref_value_t* rc_alloc_memref_value(rc_parse_state_t* parse, unsigned address, char size, char is_bcd); +void rc_update_memref_values(rc_memref_value_t* memref, rc_peek_t peek, void* ud); -rc_condset_t* rc_parse_condset(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +void rc_parse_trigger_internal(rc_trigger_t* self, const char** memaddr, rc_parse_state_t* parse); + +rc_condset_t* rc_parse_condset(const char** memaddr, rc_parse_state_t* parse); int rc_test_condset(rc_condset_t* self, int* reset, rc_peek_t peek, void* ud, lua_State* L); void rc_reset_condset(rc_condset_t* self); -rc_condition_t* rc_parse_condition(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +rc_condition_t* rc_parse_condition(const char** memaddr, rc_parse_state_t* parse); int rc_test_condition(rc_condition_t* self, unsigned add_buffer, rc_peek_t peek, void* ud, lua_State* L); -int rc_parse_operand(rc_operand_t* self, const char** memaddr, int is_trigger, lua_State* L, int funcs_ndx); +int rc_parse_operand(rc_operand_t* self, const char** memaddr, int is_trigger, rc_parse_state_t* parse); unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_State* L); -rc_term_t* rc_parse_term(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +rc_term_t* rc_parse_term(const char** memaddr, rc_parse_state_t* parse); unsigned rc_evaluate_term(rc_term_t* self, rc_peek_t peek, void* ud, lua_State* L); -rc_expression_t* rc_parse_expression(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +rc_expression_t* rc_parse_expression(const char** memaddr, rc_parse_state_t* parse); unsigned rc_evaluate_expression(rc_expression_t* self, rc_peek_t peek, void* ud, lua_State* L); -void rc_parse_value_internal(rc_value_t* self, int* ret, void* buffer, void* scratch, const char** memaddr, lua_State* L, int funcs_ndx); +void rc_parse_value_internal(rc_value_t* self, const char** memaddr, rc_parse_state_t* parse); -void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* scratch, const char* memaddr, lua_State* L, int funcs_ndx); +void rc_parse_lboard_internal(rc_lboard_t* self, const char* memaddr, rc_parse_state_t* parse); + +void rc_parse_richpresence_internal(rc_richpresence_t* self, const char* script, rc_parse_state_t* parse); #endif /* INTERNAL_H */ diff --git a/deps/rcheevos/src/rcheevos/lboard.c b/deps/rcheevos/src/rcheevos/lboard.c index 56b216cd7f..a0e8334d38 100644 --- a/deps/rcheevos/src/rcheevos/lboard.c +++ b/deps/rcheevos/src/rcheevos/lboard.c @@ -9,7 +9,7 @@ enum { RC_LBOARD_COMPLETE = RC_LBOARD_START | RC_LBOARD_CANCEL | RC_LBOARD_SUBMIT | RC_LBOARD_VALUE }; -void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* scratch, const char* memaddr, lua_State* L, int funcs_ndx) { +void rc_parse_lboard_internal(rc_lboard_t* self, const char* memaddr, rc_parse_state_t* parse) { int found; self->progress = 0; @@ -21,15 +21,16 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s (memaddr[1] == 't' || memaddr[1] == 'T') && (memaddr[2] == 'a' || memaddr[2] == 'A') && memaddr[3] == ':') { if ((found & RC_LBOARD_START) != 0) { - *ret = RC_DUPLICATED_START; + parse->offset = RC_DUPLICATED_START; return; } found |= RC_LBOARD_START; memaddr += 4; - rc_parse_trigger_internal(&self->start, ret, buffer, scratch, &memaddr, L, funcs_ndx); + rc_parse_trigger_internal(&self->start, &memaddr, parse); + self->start.memrefs = 0; - if (*ret < 0) { + if (parse->offset < 0) { return; } } @@ -37,15 +38,16 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s (memaddr[1] == 'a' || memaddr[1] == 'A') && (memaddr[2] == 'n' || memaddr[2] == 'N') && memaddr[3] == ':') { if ((found & RC_LBOARD_CANCEL) != 0) { - *ret = RC_DUPLICATED_CANCEL; + parse->offset = RC_DUPLICATED_CANCEL; return; } found |= RC_LBOARD_CANCEL; memaddr += 4; - rc_parse_trigger_internal(&self->cancel, ret, buffer, scratch, &memaddr, L, funcs_ndx); + rc_parse_trigger_internal(&self->cancel, &memaddr, parse); + self->cancel.memrefs = 0; - if (*ret < 0) { + if (parse->offset < 0) { return; } } @@ -53,15 +55,16 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s (memaddr[1] == 'u' || memaddr[1] == 'U') && (memaddr[2] == 'b' || memaddr[2] == 'B') && memaddr[3] == ':') { if ((found & RC_LBOARD_SUBMIT) != 0) { - *ret = RC_DUPLICATED_SUBMIT; + parse->offset = RC_DUPLICATED_SUBMIT; return; } found |= RC_LBOARD_SUBMIT; memaddr += 4; - rc_parse_trigger_internal(&self->submit, ret, buffer, scratch, &memaddr, L, funcs_ndx); + rc_parse_trigger_internal(&self->submit, &memaddr, parse); + self->submit.memrefs = 0; - if (*ret < 0) { + if (parse->offset < 0) { return; } } @@ -69,15 +72,16 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s (memaddr[1] == 'a' || memaddr[1] == 'A') && (memaddr[2] == 'l' || memaddr[2] == 'L') && memaddr[3] == ':') { if ((found & RC_LBOARD_VALUE) != 0) { - *ret = RC_DUPLICATED_VALUE; + parse->offset = RC_DUPLICATED_VALUE; return; } found |= RC_LBOARD_VALUE; memaddr += 4; - rc_parse_value_internal(&self->value, ret, buffer, scratch, &memaddr, L, funcs_ndx); + rc_parse_value_internal(&self->value, &memaddr, parse); + self->value.memrefs = 0; - if (*ret < 0) { + if (parse->offset < 0) { return; } } @@ -85,22 +89,23 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s (memaddr[1] == 'r' || memaddr[1] == 'R') && (memaddr[2] == 'o' || memaddr[2] == 'O') && memaddr[3] == ':') { if ((found & RC_LBOARD_PROGRESS) != 0) { - *ret = RC_DUPLICATED_PROGRESS; + parse->offset = RC_DUPLICATED_PROGRESS; return; } found |= RC_LBOARD_PROGRESS; memaddr += 4; - self->progress = RC_ALLOC(rc_value_t, buffer, ret, scratch); - rc_parse_value_internal(self->progress, ret, buffer, scratch, &memaddr, L, funcs_ndx); + self->progress = RC_ALLOC(rc_value_t, parse); + rc_parse_value_internal(self->progress, &memaddr, parse); + self->progress->memrefs = 0; - if (*ret < 0) { + if (parse->offset < 0) { return; } } else { - *ret = RC_INVALID_LBOARD_FIELD; + parse->offset = RC_INVALID_LBOARD_FIELD; return; } @@ -113,16 +118,16 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s if ((found & RC_LBOARD_COMPLETE) != RC_LBOARD_COMPLETE) { if ((found & RC_LBOARD_START) == 0) { - *ret = RC_MISSING_START; + parse->offset = RC_MISSING_START; } else if ((found & RC_LBOARD_CANCEL) == 0) { - *ret = RC_MISSING_CANCEL; + parse->offset = RC_MISSING_CANCEL; } else if ((found & RC_LBOARD_SUBMIT) == 0) { - *ret = RC_MISSING_SUBMIT; + parse->offset = RC_MISSING_SUBMIT; } else if ((found & RC_LBOARD_VALUE) == 0) { - *ret = RC_MISSING_VALUE; + parse->offset = RC_MISSING_VALUE; } return; @@ -132,31 +137,37 @@ void rc_parse_lboard_internal(rc_lboard_t* self, int* ret, void* buffer, void* s } int rc_lboard_size(const char* memaddr) { - int ret; rc_lboard_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, 0, 0, 0); - ret = 0; - self = RC_ALLOC(rc_lboard_t, 0, &ret, &scratch); - rc_parse_lboard_internal(self, &ret, 0, &scratch, memaddr, 0, 0); - return ret; + self = RC_ALLOC(rc_lboard_t, &parse); + rc_parse_lboard_internal(self, memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset; } rc_lboard_t* rc_parse_lboard(void* buffer, const char* memaddr, lua_State* L, int funcs_ndx) { - int ret; rc_lboard_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, buffer, L, funcs_ndx); - ret = 0; - self = RC_ALLOC(rc_lboard_t, buffer, &ret, &scratch); - rc_parse_lboard_internal(self, &ret, buffer, 0, memaddr, L, funcs_ndx); - return ret >= 0 ? self : 0; + self = RC_ALLOC(rc_lboard_t, &parse); + rc_init_parse_state_memrefs(&parse, &self->memrefs); + + rc_parse_lboard_internal(self, memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset >= 0 ? self : 0; } int rc_evaluate_lboard(rc_lboard_t* self, unsigned* value, rc_peek_t peek, void* peek_ud, lua_State* L) { int start_ok, cancel_ok, submit_ok; int action = -1; + rc_update_memref_values(self->memrefs, peek, peek_ud); + /* ASSERT: these are always tested once every frame, to ensure delta variables work properly */ start_ok = rc_test_trigger(&self->start, peek, peek_ud, L); cancel_ok = rc_test_trigger(&self->cancel, peek, peek_ud, L); diff --git a/deps/rcheevos/src/rcheevos/memref.c b/deps/rcheevos/src/rcheevos/memref.c new file mode 100644 index 0000000000..b4565bb679 --- /dev/null +++ b/deps/rcheevos/src/rcheevos/memref.c @@ -0,0 +1,204 @@ +#include "internal.h" + +#include /* malloc/realloc */ +#include /* memcpy */ + +rc_memref_value_t* rc_alloc_memref_value(rc_parse_state_t* parse, unsigned address, char size, char is_bcd) { + rc_memref_value_t** next_memref_value; + rc_memref_value_t* memref_value; + rc_memref_t* memref; + int i; + + if (!parse->first_memref) { + /* sizing mode - have to track unique address/size/bcd combinations */ + for (i = 0; i < parse->scratch.memref_count; ++i) { + memref = &parse->scratch.memref[i]; + if (memref->address == address && memref->size == size && memref->is_bcd == is_bcd) { + return &parse->scratch.obj.memref_value; + } + } + + /* resize unique tracking buffer if necessary */ + if (parse->scratch.memref_count == parse->scratch.memref_size) { + if (parse->scratch.memref == parse->scratch.memref_buffer) { + parse->scratch.memref_size += 16; + memref = malloc(parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); + if (memref) { + parse->scratch.memref = memref; + memcpy(memref, parse->scratch.memref_buffer, parse->scratch.memref_count * sizeof(parse->scratch.memref_buffer[0])); + } + else { + parse->offset = RC_OUT_OF_MEMORY; + return 0; + } + } + else { + parse->scratch.memref_size += 32; + memref = realloc(parse->scratch.memref, parse->scratch.memref_size * sizeof(parse->scratch.memref_buffer[0])); + if (memref) { + parse->scratch.memref = memref; + } + else { + parse->offset = RC_OUT_OF_MEMORY; + return 0; + } + } + } + + /* add new unique tracking entry */ + if (parse->scratch.memref) { + memref = &parse->scratch.memref[parse->scratch.memref_count++]; + memref->address = address; + memref->size = size; + memref->is_bcd = is_bcd; + } + + /* allocate memory but don't actually populate, as it might overwrite the self object referencing the rc_memref_value_t */ + return RC_ALLOC(rc_memref_value_t, parse); + } + + /* construction mode - find or create the appropriate rc_memref_value_t */ + next_memref_value = parse->first_memref; + while (*next_memref_value) { + memref_value = *next_memref_value; + if (memref_value->memref.address == address && memref_value->memref.size == size && memref_value->memref.is_bcd == is_bcd) { + return memref_value; + } + + next_memref_value = &memref_value->next; + } + + memref_value = RC_ALLOC(rc_memref_value_t, parse); + memref_value->memref.address = address; + memref_value->memref.size = size; + memref_value->memref.is_bcd = is_bcd; + memref_value->value = 0; + memref_value->previous = 0; + memref_value->prior = 0; + memref_value->next = 0; + + *next_memref_value = memref_value; + + return memref_value; +} + +static unsigned rc_memref_get_value(rc_memref_t* self, rc_peek_t peek, void* ud) { + unsigned value; + + switch (self->size) + { + case RC_MEMSIZE_BIT_0: + value = (peek(self->address, 1, ud) >> 0) & 1; + break; + + case RC_MEMSIZE_BIT_1: + value = (peek(self->address, 1, ud) >> 1) & 1; + break; + + case RC_MEMSIZE_BIT_2: + value = (peek(self->address, 1, ud) >> 2) & 1; + break; + + case RC_MEMSIZE_BIT_3: + value = (peek(self->address, 1, ud) >> 3) & 1; + break; + + case RC_MEMSIZE_BIT_4: + value = (peek(self->address, 1, ud) >> 4) & 1; + break; + + case RC_MEMSIZE_BIT_5: + value = (peek(self->address, 1, ud) >> 5) & 1; + break; + + case RC_MEMSIZE_BIT_6: + value = (peek(self->address, 1, ud) >> 6) & 1; + break; + + case RC_MEMSIZE_BIT_7: + value = (peek(self->address, 1, ud) >> 7) & 1; + break; + + case RC_MEMSIZE_LOW: + value = peek(self->address, 1, ud) & 0x0f; + break; + + case RC_MEMSIZE_HIGH: + value = (peek(self->address, 1, ud) >> 4) & 0x0f; + break; + + case RC_MEMSIZE_8_BITS: + value = peek(self->address, 1, ud); + + if (self->is_bcd) { + value = ((value >> 4) & 0x0f) * 10 + (value & 0x0f); + } + + break; + + case RC_MEMSIZE_16_BITS: + value = peek(self->address, 2, ud); + + if (self->is_bcd) { + value = ((value >> 12) & 0x0f) * 1000 + + ((value >> 8) & 0x0f) * 100 + + ((value >> 4) & 0x0f) * 10 + + ((value >> 0) & 0x0f) * 1; + } + + break; + + case RC_MEMSIZE_24_BITS: + value = peek(self->address, 4, ud); + + if (self->is_bcd) { + value = ((value >> 20) & 0x0f) * 100000 + + ((value >> 16) & 0x0f) * 10000 + + ((value >> 12) & 0x0f) * 1000 + + ((value >> 8) & 0x0f) * 100 + + ((value >> 4) & 0x0f) * 10 + + ((value >> 0) & 0x0f) * 1; + } + + break; + + case RC_MEMSIZE_32_BITS: + value = peek(self->address, 4, ud); + + if (self->is_bcd) { + value = ((value >> 28) & 0x0f) * 10000000 + + ((value >> 24) & 0x0f) * 1000000 + + ((value >> 20) & 0x0f) * 100000 + + ((value >> 16) & 0x0f) * 10000 + + ((value >> 12) & 0x0f) * 1000 + + ((value >> 8) & 0x0f) * 100 + + ((value >> 4) & 0x0f) * 10 + + ((value >> 0) & 0x0f) * 1; + } + + break; + + default: + value = 0; + break; + } + + return value; +} + +void rc_update_memref_values(rc_memref_value_t* memref, rc_peek_t peek, void* ud) { + while (memref) { + memref->previous = memref->value; + memref->value = rc_memref_get_value(&memref->memref, peek, ud); + if (memref->value != memref->previous) + memref->prior = memref->previous; + + memref = memref->next; + } +} + +void rc_init_parse_state_memrefs(rc_parse_state_t* parse, rc_memref_value_t** memrefs) +{ + parse->first_memref = memrefs; + *memrefs = 0; +} diff --git a/deps/rcheevos/src/rcheevos/operand.c b/deps/rcheevos/src/rcheevos/operand.c index 1e760daa16..85502fbd1f 100644 --- a/deps/rcheevos/src/rcheevos/operand.c +++ b/deps/rcheevos/src/rcheevos/operand.c @@ -2,6 +2,7 @@ #include #include +#include #ifndef RC_DISABLE_LUA @@ -18,7 +19,7 @@ extern "C" { #endif /* RC_DISABLE_LUA */ -static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_State* L, int funcs_ndx) { +static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { const char* aux = *memaddr; const char* id; @@ -38,20 +39,20 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_St #ifndef RC_DISABLE_LUA - if (L != 0) { - if (!lua_istable(L, funcs_ndx)) { + if (parse->L != 0) { + if (!lua_istable(parse->L, parse->funcs_ndx)) { return RC_INVALID_LUA_OPERAND; } - lua_pushlstring(L, id, aux - id); - lua_gettable(L, funcs_ndx); + lua_pushlstring(parse->L, id, aux - id); + lua_gettable(parse->L, parse->funcs_ndx); - if (!lua_isfunction(L, -1)) { - lua_pop(L, 1); + if (!lua_isfunction(parse->L, -1)) { + lua_pop(parse->L, 1); return RC_INVALID_LUA_OPERAND; } - self->function_ref = luaL_ref(L, LUA_REGISTRYINDEX); + self->function_ref = luaL_ref(parse->L, LUA_REGISTRYINDEX); } #endif /* RC_DISABLE_LUA */ @@ -61,10 +62,12 @@ static int rc_parse_operand_lua(rc_operand_t* self, const char** memaddr, lua_St return RC_OK; } -static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr) { +static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { const char* aux = *memaddr; char* end; - unsigned long value; + unsigned long address; + char is_bcd = 0; + char size; switch (*aux++) { case 'd': case 'D': @@ -73,7 +76,11 @@ static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr) { case 'b': case 'B': self->type = RC_OPERAND_ADDRESS; - self->is_bcd = 1; + is_bcd = 1; + break; + + case 'p': case 'P': + self->type = RC_OPERAND_PRIOR; break; default: @@ -93,44 +100,46 @@ static int rc_parse_operand_memory(rc_operand_t* self, const char** memaddr) { aux++; switch (*aux++) { - case 'm': case 'M': self->size = RC_OPERAND_BIT_0; break; - case 'n': case 'N': self->size = RC_OPERAND_BIT_1; break; - case 'o': case 'O': self->size = RC_OPERAND_BIT_2; break; - case 'p': case 'P': self->size = RC_OPERAND_BIT_3; break; - case 'q': case 'Q': self->size = RC_OPERAND_BIT_4; break; - case 'r': case 'R': self->size = RC_OPERAND_BIT_5; break; - case 's': case 'S': self->size = RC_OPERAND_BIT_6; break; - case 't': case 'T': self->size = RC_OPERAND_BIT_7; break; - case 'l': case 'L': self->size = RC_OPERAND_LOW; break; - case 'u': case 'U': self->size = RC_OPERAND_HIGH; break; - case 'h': case 'H': self->size = RC_OPERAND_8_BITS; break; - case 'w': case 'W': self->size = RC_OPERAND_24_BITS; break; - case 'x': case 'X': self->size = RC_OPERAND_32_BITS; break; + case 'm': case 'M': size = RC_MEMSIZE_BIT_0; break; + case 'n': case 'N': size = RC_MEMSIZE_BIT_1; break; + case 'o': case 'O': size = RC_MEMSIZE_BIT_2; break; + case 'p': case 'P': size = RC_MEMSIZE_BIT_3; break; + case 'q': case 'Q': size = RC_MEMSIZE_BIT_4; break; + case 'r': case 'R': size = RC_MEMSIZE_BIT_5; break; + case 's': case 'S': size = RC_MEMSIZE_BIT_6; break; + case 't': case 'T': size = RC_MEMSIZE_BIT_7; break; + case 'l': case 'L': size = RC_MEMSIZE_LOW; break; + case 'u': case 'U': size = RC_MEMSIZE_HIGH; break; + case 'h': case 'H': size = RC_MEMSIZE_8_BITS; break; + case 'w': case 'W': size = RC_MEMSIZE_24_BITS; break; + case 'x': case 'X': size = RC_MEMSIZE_32_BITS; break; default: /* fall through */ aux--; case ' ': - self->size = RC_OPERAND_16_BITS; + size = RC_MEMSIZE_16_BITS; break; } - value = (unsigned)strtoul(aux, &end, 16); + address = strtoul(aux, &end, 16); if (end == aux) { return RC_INVALID_MEMORY_OPERAND; } - if (value > 0xffffffffU) { - value = 0xffffffffU; + if (address > 0xffffffffU) { + address = 0xffffffffU; } - self->value = (unsigned)value; + self->memref = rc_alloc_memref_value(parse, address, size, is_bcd); + if (parse->offset < 0) + return parse->offset; *memaddr = end; return RC_OK; } -static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, lua_State* L, int funcs_ndx) { +static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { const char* aux = *memaddr; char* end; int ret; @@ -158,7 +167,7 @@ static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, lu if (aux[1] == 'x' || aux[1] == 'X') { /* fall through */ default: - ret = rc_parse_operand_memory(self, &aux); + ret = rc_parse_operand_memory(self, &aux, parse); if (ret < 0) { return ret; @@ -188,7 +197,7 @@ static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, lu break; case '@': - ret = rc_parse_operand_lua(self, &aux, L, funcs_ndx); + ret = rc_parse_operand_lua(self, &aux, parse); if (ret < 0) { return ret; @@ -201,7 +210,7 @@ static int rc_parse_operand_trigger(rc_operand_t* self, const char** memaddr, lu return RC_OK; } -static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_State* L, int funcs_ndx) { +static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, rc_parse_state_t* parse) { const char* aux = *memaddr; char* end; int ret; @@ -209,7 +218,7 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_S switch (*aux) { case 'h': case 'H': - value = (unsigned)strtoul(++aux, &end, 16); + value = strtoul(++aux, &end, 16); if (end == aux) { return RC_INVALID_CONST_OPERAND; @@ -226,7 +235,7 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_S break; case 'v': case 'V': - value = (unsigned)strtoul(++aux, &end, 10); + value = strtoul(++aux, &end, 10); if (end == aux) { return RC_INVALID_CONST_OPERAND; @@ -246,7 +255,7 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_S if (aux[1] == 'x' || aux[1] == 'X') { /* fall through */ default: - ret = rc_parse_operand_memory(self, &aux); + ret = rc_parse_operand_memory(self, &aux, parse); if (ret < 0) { return ret; @@ -256,21 +265,28 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_S } /* fall through */ + case '.': case '+': case '-': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - self->type = RC_OPERAND_FP; self->fp_value = strtod(aux, &end); if (end == aux) { return RC_INVALID_FP_OPERAND; } + if (floor(self->fp_value) == self->fp_value) { + self->type = RC_OPERAND_CONST; + self->value = (unsigned)floor(self->fp_value); + } + else { + self->type = RC_OPERAND_FP; + } aux = end; break; case '@': - ret = rc_parse_operand_lua(self, &aux, L, funcs_ndx); + ret = rc_parse_operand_lua(self, &aux, parse); if (ret < 0) { return ret; @@ -283,16 +299,12 @@ static int rc_parse_operand_term(rc_operand_t* self, const char** memaddr, lua_S return RC_OK; } -int rc_parse_operand(rc_operand_t* self, const char** memaddr, int is_trigger, lua_State* L, int funcs_ndx) { - self->size = RC_OPERAND_8_BITS; - self->is_bcd = 0; - self->previous = 0; - +int rc_parse_operand(rc_operand_t* self, const char** memaddr, int is_trigger, rc_parse_state_t* parse) { if (is_trigger) { - return rc_parse_operand_trigger(self, memaddr, L, funcs_ndx); + return rc_parse_operand_trigger(self, memaddr, parse); } else { - return rc_parse_operand_term(self, memaddr, L, funcs_ndx); + return rc_parse_operand_term(self, memaddr, parse); } } @@ -362,106 +374,15 @@ unsigned rc_evaluate_operand(rc_operand_t* self, rc_peek_t peek, void* ud, lua_S break; case RC_OPERAND_ADDRESS: + value = self->memref->value; + break; + case RC_OPERAND_DELTA: - switch (self->size) { - case RC_OPERAND_BIT_0: - value = (peek(self->value, 1, ud) >> 0) & 1; - break; - - case RC_OPERAND_BIT_1: - value = (peek(self->value, 1, ud) >> 1) & 1; - break; - - case RC_OPERAND_BIT_2: - value = (peek(self->value, 1, ud) >> 2) & 1; - break; - - case RC_OPERAND_BIT_3: - value = (peek(self->value, 1, ud) >> 3) & 1; - break; - - case RC_OPERAND_BIT_4: - value = (peek(self->value, 1, ud) >> 4) & 1; - break; - - case RC_OPERAND_BIT_5: - value = (peek(self->value, 1, ud) >> 5 ) & 1; - break; - - case RC_OPERAND_BIT_6: - value = (peek(self->value, 1, ud) >> 6) & 1; - break; - - case RC_OPERAND_BIT_7: - value = (peek(self->value, 1, ud) >> 7) & 1; - break; - - case RC_OPERAND_LOW: - value = peek(self->value, 1, ud) & 0x0f; - break; - - case RC_OPERAND_HIGH: - value = (peek(self->value, 1, ud) >> 4) & 0x0f; - break; - - case RC_OPERAND_8_BITS: - value = peek(self->value, 1, ud); - - if (self->is_bcd) { - value = ((value >> 4) & 0x0f) * 10 + (value & 0x0f); - } - - break; - - case RC_OPERAND_16_BITS: - value = peek(self->value, 2, ud); - - if (self->is_bcd) { - value = ((value >> 12) & 0x0f) * 1000 - + ((value >> 8) & 0x0f) * 100 - + ((value >> 4) & 0x0f) * 10 - + ((value >> 0) & 0x0f) * 1; - } - - break; - - case RC_OPERAND_24_BITS: - value = peek(self->value, 4, ud); - - if (self->is_bcd) { - value = ((value >> 20) & 0x0f) * 100000 - + ((value >> 16) & 0x0f) * 10000 - + ((value >> 12) & 0x0f) * 1000 - + ((value >> 8) & 0x0f) * 100 - + ((value >> 4) & 0x0f) * 10 - + ((value >> 0) & 0x0f) * 1; - } - - break; - - case RC_OPERAND_32_BITS: - value = peek(self->value, 4, ud); - - if (self->is_bcd) { - value = ((value >> 28) & 0x0f) * 10000000 - + ((value >> 24) & 0x0f) * 1000000 - + ((value >> 20) & 0x0f) * 100000 - + ((value >> 16) & 0x0f) * 10000 - + ((value >> 12) & 0x0f) * 1000 - + ((value >> 8) & 0x0f) * 100 - + ((value >> 4) & 0x0f) * 10 - + ((value >> 0) & 0x0f) * 1; - } - - break; - } - - if (self->type == RC_OPERAND_DELTA) { - unsigned previous = self->previous; - self->previous = value; - value = previous; - } + value = self->memref->previous; + break; + case RC_OPERAND_PRIOR: + value = self->memref->prior; break; } diff --git a/deps/rcheevos/src/rcheevos/richpresence.c b/deps/rcheevos/src/rcheevos/richpresence.c new file mode 100644 index 0000000000..85a7a51f57 --- /dev/null +++ b/deps/rcheevos/src/rcheevos/richpresence.c @@ -0,0 +1,430 @@ +#include "internal.h" + +#include +#include +#include +#include + +/* special formats only used by rc_richpresence_display_part_t.display_type. must not overlap other RC_FORMAT values */ +enum { + RC_FORMAT_STRING = 101, + RC_FORMAT_LOOKUP = 102 +}; + +static const char* rc_parse_line(const char* line, const char** end) { + const char* nextline; + const char* endline; + + /* get a single line */ + nextline = line; + while (*nextline && *nextline != '\n') + ++nextline; + + /* find a trailing comment marker (//) */ + endline = line; + while (endline < nextline && (endline[0] != '/' || endline[1] != '/' || (endline > line && endline[-1] == '\\'))) + ++endline; + + /* remove trailing whitespace */ + if (endline == nextline) { + if (endline > line && endline[-1] == '\r') + --endline; + } else { + while (endline > line && isspace(endline[-1])) + --endline; + } + + /* end is pointing at the first character to ignore - makes subtraction for length easier */ + *end = endline; + + if (*nextline == '\n') + ++nextline; + return nextline; +} + +static rc_richpresence_display_t* rc_parse_richpresence_display_internal(const char* line, const char* endline, rc_parse_state_t* parse, rc_richpresence_t* richpresence) { + rc_richpresence_display_t* self; + rc_richpresence_display_part_t* part; + rc_richpresence_display_part_t** next; + rc_richpresence_lookup_t* lookup; + const char* ptr; + const char* in; + char* out; + + if (endline - line < 1) + return 0; + + { + self = RC_ALLOC(rc_richpresence_display_t, parse); + memset(self, 0, sizeof(rc_richpresence_display_t)); + next = &self->display; + } + + /* break the string up on macros: text @macro() moretext */ + do { + ptr = line; + while (ptr < endline) { + if (*ptr == '@' && (ptr == line || ptr[-1] != '\\')) /* ignore escaped @s */ + break; + + ++ptr; + } + + if (ptr > line) { + part = RC_ALLOC(rc_richpresence_display_part_t, parse); + memset(part, 0, sizeof(rc_richpresence_display_part_t)); + *next = part; + next = &part->next; + + /* handle string part */ + part->display_type = RC_FORMAT_STRING; + part->text = rc_alloc_str(parse, line, ptr - line); + if (part->text) { + /* remove backslashes used for escaping */ + in = part->text; + while (*in && *in != '\\') + ++in; + + if (*in == '\\') { + out = (char*)in++; + while (*in) { + *out++ = *in++; + if (*in == '\\') + ++in; + } + *out = '\0'; + } + } + } + + if (*ptr == '@') { + /* handle macro part */ + line = ++ptr; + while (ptr < endline && *ptr != '(') + ++ptr; + + if (ptr > line) { + if (!parse->buffer) { + /* just calculating size, can't confirm lookup exists */ + part = RC_ALLOC(rc_richpresence_display_part_t, parse); + + line = ++ptr; + while (ptr < endline && *ptr != ')') + ++ptr; + if (*ptr == ')') { + rc_parse_value_internal(&part->value, &line, parse); + if (parse->offset < 0) + return 0; + ++ptr; + } + + } else { + /* find the lookup and hook it up */ + lookup = richpresence->first_lookup; + while (lookup) { + if (strncmp(lookup->name, line, ptr - line) == 0 && lookup->name[ptr - line] == '\0') { + part = RC_ALLOC(rc_richpresence_display_part_t, parse); + *next = part; + next = &part->next; + + part->text = lookup->name; + part->first_lookup_item = lookup->first_item; + part->display_type = lookup->format; + + line = ++ptr; + while (ptr < endline && *ptr != ')') + ++ptr; + if (*ptr == ')') { + rc_parse_value_internal(&part->value, &line, parse); + part->value.memrefs = 0; + if (parse->offset < 0) + return 0; + ++ptr; + } + + break; + } + + lookup = lookup->next; + } + + if (!lookup) { + part = RC_ALLOC(rc_richpresence_display_part_t, parse); + memset(part, 0, sizeof(rc_richpresence_display_part_t)); + *next = part; + next = &part->next; + + ptr = line; + + part->display_type = RC_FORMAT_STRING; + part->text = rc_alloc_str(parse, "[Unknown macro]", 15); + } + } + } + } + + line = ptr; + } while (line < endline); + + *next = 0; + + return self; +} + +static const char* rc_parse_richpresence_lookup(rc_richpresence_lookup_t* lookup, const char* nextline, rc_parse_state_t* parse) +{ + rc_richpresence_lookup_item_t** next; + rc_richpresence_lookup_item_t* item; + char number[64]; + const char* line; + const char* endline; + const char* defaultlabel = 0; + unsigned key; + int chars; + + next = &lookup->first_item; + + do + { + line = nextline; + nextline = rc_parse_line(line, &endline); + + if (endline - line < 2) + break; + + chars = 0; + while (chars < (sizeof(number) - 1) && line + chars < endline && line[chars] != '=') { + number[chars] = line[chars]; + ++chars; + } + number[chars] = '\0'; + + if (line[chars] == '=') { + line += chars + 1; + + if (chars == 1 && number[0] == '*') { + defaultlabel = rc_alloc_str(parse, line, endline - line); + continue; + } + + if (number[0] == '0' && number[1] == 'x') + key = strtoul(&number[2], 0, 16); + else + key = strtoul(&number[0], 0, 10); + + item = RC_ALLOC(rc_richpresence_lookup_item_t, parse); + item->value = key; + item->label = rc_alloc_str(parse, line, endline - line); + *next = item; + next = &item->next_item; + } + } while (1); + + if (!defaultlabel) + defaultlabel = rc_alloc_str(parse, "", 0); + + item = RC_ALLOC(rc_richpresence_lookup_item_t, parse); + item->value = 0; + item->label = defaultlabel; + item->next_item = 0; + *next = item; + + return nextline; +} + +void rc_parse_richpresence_internal(rc_richpresence_t* self, const char* script, rc_parse_state_t* parse) { + rc_richpresence_display_t** nextdisplay; + rc_richpresence_lookup_t** nextlookup; + rc_richpresence_lookup_t* lookup; + rc_trigger_t* trigger; + char format[64]; + const char* display = 0; + const char* line; + const char* nextline; + const char* endline; + const char* ptr; + int hasdisplay = 0; + int chars; + + nextlookup = &self->first_lookup; + + /* first pass: process macro initializers */ + line = script; + while (*line) + { + nextline = rc_parse_line(line, &endline); + if (strncmp(line, "Lookup:", 7) == 0) { + line += 7; + + lookup = RC_ALLOC(rc_richpresence_lookup_t, parse); + lookup->name = rc_alloc_str(parse, line, endline - line); + lookup->format = RC_FORMAT_LOOKUP; + *nextlookup = lookup; + nextlookup = &lookup->next; + + nextline = rc_parse_richpresence_lookup(lookup, nextline, parse); + + } else if (strncmp(line, "Format:", 7) == 0) { + line += 7; + + lookup = RC_ALLOC(rc_richpresence_lookup_t, parse); + lookup->name = rc_alloc_str(parse, line, endline - line); + lookup->first_item = 0; + *nextlookup = lookup; + nextlookup = &lookup->next; + + line = nextline; + nextline = rc_parse_line(line, &endline); + if (parse->buffer && strncmp(line, "FormatType=", 11) == 0) { + line += 11; + + chars = endline - line; + if (chars > 63) + chars = 63; + memcpy(format, line, chars); + format[chars] = '\0'; + + lookup->format = rc_parse_format(format); + } else { + lookup->format = RC_FORMAT_VALUE; + } + } else if (strncmp(line, "Display:", 8) == 0) { + display = nextline; + + do { + line = nextline; + nextline = rc_parse_line(line, &endline); + } while (*line == '?'); + } + + line = nextline; + } + + *nextlookup = 0; + nextdisplay = &self->first_display; + + /* second pass, process display string*/ + if (display) { + line = display; + nextline = rc_parse_line(line, &endline); + + while (*line == '?') { + /* conditional display: ?trigger?string */ + ptr = ++line; + while (ptr < endline && *ptr != '?') + ++ptr; + + if (ptr < endline) { + *nextdisplay = rc_parse_richpresence_display_internal(ptr + 1, endline, parse, self); + trigger = &((*nextdisplay)->trigger); + rc_parse_trigger_internal(trigger, &line, parse); + trigger->memrefs = 0; + if (parse->offset < 0) + return; + if (parse->buffer) + nextdisplay = &((*nextdisplay)->next); + } + + line = nextline; + nextline = rc_parse_line(line, &endline); + } + + /* non-conditional display: string */ + *nextdisplay = rc_parse_richpresence_display_internal(line, endline, parse, self); + if (*nextdisplay) { + hasdisplay = 1; + nextdisplay = &((*nextdisplay)->next); + } + } + + /* finalize */ + *nextdisplay = 0; + + if (!hasdisplay && parse->offset > 0) { + parse->offset = RC_MISSING_DISPLAY_STRING; + } +} + +int rc_richpresence_size(const char* script) { + rc_richpresence_t* self; + rc_parse_state_t parse; + rc_init_parse_state(&parse, 0, 0, 0); + + self = RC_ALLOC(rc_richpresence_t, &parse); + rc_parse_richpresence_internal(self, script, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset; +} + +rc_richpresence_t* rc_parse_richpresence(void* buffer, const char* script, lua_State* L, int funcs_ndx) { + rc_richpresence_t* self; + rc_parse_state_t parse; + rc_init_parse_state(&parse, buffer, L, funcs_ndx); + + self = RC_ALLOC(rc_richpresence_t, &parse); + rc_init_parse_state_memrefs(&parse, &self->memrefs); + + rc_parse_richpresence_internal(self, script, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset >= 0 ? self : 0; +} + +int rc_evaluate_richpresence(rc_richpresence_t* richpresence, char* buffer, unsigned buffersize, rc_peek_t peek, void* peek_ud, lua_State* L) { + rc_richpresence_display_t* display; + rc_richpresence_display_part_t* part; + rc_richpresence_lookup_item_t* item; + char* ptr; + int chars; + unsigned value; + + rc_update_memref_values(richpresence->memrefs, peek, peek_ud); + + ptr = buffer; + display = richpresence->first_display; + while (display) { + if (!display->next || rc_test_trigger(&display->trigger, peek, peek_ud, L)) { + part = display->display; + while (part) { + switch (part->display_type) { + case RC_FORMAT_STRING: + chars = snprintf(ptr, buffersize, "%s", part->text); + break; + + case RC_FORMAT_LOOKUP: + value = rc_evaluate_value(&part->value, peek, peek_ud, L); + item = part->first_lookup_item; + if (!item) { + chars = 0; + } else { + while (item->next_item && item->value != value) + item = item->next_item; + + chars = snprintf(ptr, buffersize, "%s", item->label); + } + break; + + default: + value = rc_evaluate_value(&part->value, peek, peek_ud, L); + chars = rc_format_value(ptr, buffersize, value, part->display_type); + break; + } + + if (chars > 0) { + ptr += chars; + buffersize -= chars; + } + + part = part->next; + } + + return (ptr - buffer); + } + + display = display->next; + } + + buffer[0] = '\0'; + return 0; +} diff --git a/deps/rcheevos/src/rcheevos/term.c b/deps/rcheevos/src/rcheevos/term.c index 33019fa54c..de4e01e048 100644 --- a/deps/rcheevos/src/rcheevos/term.c +++ b/deps/rcheevos/src/rcheevos/term.c @@ -1,18 +1,19 @@ #include "internal.h" -rc_term_t* rc_parse_term(int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +rc_term_t* rc_parse_term(const char** memaddr, rc_parse_state_t* parse) { rc_term_t* self; const char* aux; + char size; int ret2; aux = *memaddr; - self = RC_ALLOC(rc_term_t, buffer, ret, scratch); + self = RC_ALLOC(rc_term_t, parse); self->invert = 0; - ret2 = rc_parse_operand(&self->operand1, &aux, 0, L, funcs_ndx); + ret2 = rc_parse_operand(&self->operand1, &aux, 0, parse); if (ret2 < 0) { - *ret = ret2; + parse->offset = ret2; return 0; } @@ -24,53 +25,63 @@ rc_term_t* rc_parse_term(int* ret, void* buffer, rc_scratch_t* scratch, const ch self->invert = 1; } - ret2 = rc_parse_operand(&self->operand2, &aux, 0, L, funcs_ndx); + ret2 = rc_parse_operand(&self->operand2, &aux, 0, parse); if (ret2 < 0) { - *ret = ret2; + parse->offset = ret2; return 0; } if (self->invert) { - switch (self->operand2.size) { - case RC_OPERAND_BIT_0: - case RC_OPERAND_BIT_1: - case RC_OPERAND_BIT_2: - case RC_OPERAND_BIT_3: - case RC_OPERAND_BIT_4: - case RC_OPERAND_BIT_5: - case RC_OPERAND_BIT_6: - case RC_OPERAND_BIT_7: + switch (self->operand2.type) { + case RC_OPERAND_ADDRESS: + case RC_OPERAND_DELTA: + case RC_OPERAND_PRIOR: + size = self->operand2.memref->memref.size; + break; + default: + size = RC_MEMSIZE_32_BITS; + break; + } + + switch (size) { + case RC_MEMSIZE_BIT_0: + case RC_MEMSIZE_BIT_1: + case RC_MEMSIZE_BIT_2: + case RC_MEMSIZE_BIT_3: + case RC_MEMSIZE_BIT_4: + case RC_MEMSIZE_BIT_5: + case RC_MEMSIZE_BIT_6: + case RC_MEMSIZE_BIT_7: /* invert is already 1 */ break; - case RC_OPERAND_LOW: - case RC_OPERAND_HIGH: + case RC_MEMSIZE_LOW: + case RC_MEMSIZE_HIGH: self->invert = 0xf; break; - case RC_OPERAND_8_BITS: + case RC_MEMSIZE_8_BITS: self->invert = 0xffU; break; - case RC_OPERAND_16_BITS: + case RC_MEMSIZE_16_BITS: self->invert = 0xffffU; break; - case RC_OPERAND_24_BITS: + case RC_MEMSIZE_24_BITS: self->invert = 0xffffffU; break; - case RC_OPERAND_32_BITS: + case RC_MEMSIZE_32_BITS: self->invert = 0xffffffffU; break; } } } else { - self->operand2.type = RC_OPERAND_FP; - self->operand2.size = RC_OPERAND_8_BITS; - self->operand2.fp_value = 1.0; + self->operand2.type = RC_OPERAND_CONST; + self->operand2.value = 1; } *memaddr = aux; @@ -84,5 +95,5 @@ unsigned rc_evaluate_term(rc_term_t* self, rc_peek_t peek, void* ud, lua_State* return value * (rc_evaluate_operand(&self->operand2, peek, ud, L) ^ self->invert); } - return (unsigned)(value * self->operand2.fp_value); + return (unsigned)((double)value * self->operand2.fp_value); } diff --git a/deps/rcheevos/src/rcheevos/trigger.c b/deps/rcheevos/src/rcheevos/trigger.c index bbc6cae080..90c3388164 100644 --- a/deps/rcheevos/src/rcheevos/trigger.c +++ b/deps/rcheevos/src/rcheevos/trigger.c @@ -2,7 +2,7 @@ #include -void rc_parse_trigger_internal(rc_trigger_t* self, int* ret, void* buffer, rc_scratch_t* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +void rc_parse_trigger_internal(rc_trigger_t* self, const char** memaddr, rc_parse_state_t* parse) { rc_condset_t** next; const char* aux; @@ -13,18 +13,20 @@ void rc_parse_trigger_internal(rc_trigger_t* self, int* ret, void* buffer, rc_sc self->requirement = 0; } else { - self->requirement = rc_parse_condset(ret, buffer, scratch, &aux, L, funcs_ndx); + self->requirement = rc_parse_condset(&aux, parse); - if (*ret < 0) { + if (parse->offset < 0) { return; } + + self->requirement->next = 0; } while (*aux == 's' || *aux == 'S') { aux++; - *next = rc_parse_condset(ret, buffer, scratch, &aux, L, funcs_ndx); + *next = rc_parse_condset(&aux, parse); - if (*ret < 0) { + if (parse->offset < 0) { return; } @@ -36,31 +38,37 @@ void rc_parse_trigger_internal(rc_trigger_t* self, int* ret, void* buffer, rc_sc } int rc_trigger_size(const char* memaddr) { - int ret; rc_trigger_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, 0, 0, 0); - ret = 0; - self = RC_ALLOC(rc_trigger_t, 0, &ret, &scratch); - rc_parse_trigger_internal(self, &ret, 0, &scratch, &memaddr, 0, 0); - return ret; + self = RC_ALLOC(rc_trigger_t, &parse); + rc_parse_trigger_internal(self, &memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset; } rc_trigger_t* rc_parse_trigger(void* buffer, const char* memaddr, lua_State* L, int funcs_ndx) { - int ret; rc_trigger_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, buffer, L, funcs_ndx); - ret = 0; - self = RC_ALLOC(rc_trigger_t, buffer, &ret, &scratch); - rc_parse_trigger_internal(self, &ret, buffer, 0, &memaddr, L, funcs_ndx); - return ret >= 0 ? self : 0; + self = RC_ALLOC(rc_trigger_t, &parse); + rc_init_parse_state_memrefs(&parse, &self->memrefs); + + rc_parse_trigger_internal(self, &memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset >= 0 ? self : 0; } int rc_test_trigger(rc_trigger_t* self, rc_peek_t peek, void* ud, lua_State* L) { int ret, reset; rc_condset_t* condset; + rc_update_memref_values(self->memrefs, peek, ud); + reset = 0; ret = self->requirement != 0 ? rc_test_condset(self->requirement, &reset, peek, ud, L) : 1; condset = self->alternative; diff --git a/deps/rcheevos/src/rcheevos/value.c b/deps/rcheevos/src/rcheevos/value.c index 538088c68f..7320414a3e 100644 --- a/deps/rcheevos/src/rcheevos/value.c +++ b/deps/rcheevos/src/rcheevos/value.c @@ -1,14 +1,14 @@ #include "internal.h" -void rc_parse_value_internal(rc_value_t* self, int* ret, void* buffer, void* scratch, const char** memaddr, lua_State* L, int funcs_ndx) { +void rc_parse_value_internal(rc_value_t* self, const char** memaddr, rc_parse_state_t* parse) { rc_expression_t** next; next = &self->expressions; for (;;) { - *next = rc_parse_expression(ret, buffer, scratch, memaddr, L, funcs_ndx); + *next = rc_parse_expression(memaddr, parse); - if (*ret < 0) { + if (parse->offset < 0) { return; } @@ -25,31 +25,37 @@ void rc_parse_value_internal(rc_value_t* self, int* ret, void* buffer, void* scr } int rc_value_size(const char* memaddr) { - int ret; rc_value_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, 0, 0, 0); - ret = 0; - self = RC_ALLOC(rc_value_t, 0, &ret, &scratch); - rc_parse_value_internal(self, &ret, 0, &scratch, &memaddr, 0, 0); - return ret; + self = RC_ALLOC(rc_value_t, &parse); + rc_parse_value_internal(self, &memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset; } rc_value_t* rc_parse_value(void* buffer, const char* memaddr, lua_State* L, int funcs_ndx) { - int ret; rc_value_t* self; - rc_scratch_t scratch; + rc_parse_state_t parse; + rc_init_parse_state(&parse, buffer, L, funcs_ndx); - ret = 0; - self = RC_ALLOC(rc_value_t, buffer, &ret, &scratch); - rc_parse_value_internal(self, &ret, buffer, 0, &memaddr, L, funcs_ndx); - return ret >= 0 ? self : 0; + self = RC_ALLOC(rc_value_t, &parse); + rc_init_parse_state_memrefs(&parse, &self->memrefs); + + rc_parse_value_internal(self, &memaddr, &parse); + + rc_destroy_parse_state(&parse); + return parse.offset >= 0 ? self : 0; } unsigned rc_evaluate_value(rc_value_t* self, rc_peek_t peek, void* ud, lua_State* L) { rc_expression_t* exp; unsigned value, max; + rc_update_memref_values(self->memrefs, peek, ud); + exp = self->expressions; max = rc_evaluate_expression(exp, peek, ud, L); diff --git a/deps/rcheevos/test/Makefile b/deps/rcheevos/test/Makefile deleted file mode 100644 index 3900938851..0000000000 --- a/deps/rcheevos/test/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -RC_SRC=../src/rcheevos -RC_URL_SRC=../src/rurl -LUA_SRC=lua/src - -OBJ=$(RC_SRC)/trigger.o $(RC_SRC)/condset.o $(RC_SRC)/condition.o $(RC_SRC)/operand.o \ - $(RC_SRC)/term.o $(RC_SRC)/expression.o $(RC_SRC)/value.o $(RC_SRC)/lboard.o \ - $(RC_SRC)/alloc.o $(RC_SRC)/format.o \ - $(RC_URL_SRC)/url.o \ - $(LUA_SRC)/lapi.o $(LUA_SRC)/lcode.o $(LUA_SRC)/lctype.o $(LUA_SRC)/ldebug.o \ - $(LUA_SRC)/ldo.o $(LUA_SRC)/ldump.o $(LUA_SRC)/lfunc.o $(LUA_SRC)/lgc.o $(LUA_SRC)/llex.o \ - $(LUA_SRC)/lmem.o $(LUA_SRC)/lobject.o $(LUA_SRC)/lopcodes.o $(LUA_SRC)/lparser.o \ - $(LUA_SRC)/lstate.o $(LUA_SRC)/lstring.o $(LUA_SRC)/ltable.o $(LUA_SRC)/ltm.o \ - $(LUA_SRC)/lundump.o $(LUA_SRC)/lvm.o $(LUA_SRC)/lzio.o $(LUA_SRC)/lauxlib.o \ - $(LUA_SRC)/lbaselib.o $(LUA_SRC)/lbitlib.o $(LUA_SRC)/lcorolib.o $(LUA_SRC)/ldblib.o \ - $(LUA_SRC)/liolib.o $(LUA_SRC)/lmathlib.o $(LUA_SRC)/loslib.o $(LUA_SRC)/lstrlib.o \ - $(LUA_SRC)/ltablib.o $(LUA_SRC)/lutf8lib.o $(LUA_SRC)/loadlib.o $(LUA_SRC)/linit.o \ - test.o - -all: test - -%.o: %.c - gcc -Wall -O0 -g -std=c89 -ansi -Wno-long-long -DLUA_32BITS -I../include -I$(RC_SRC) -I$(LUA_SRC) -c $< -o $@ - -test: $(OBJ) - gcc -o $@ $+ -lm - -test.o: smw_snes.h galaga_nes.h - -smw_snes.h: smw_snes.json - xxd -i $< | sed "s@unsigned@const@" > $@ - -galaga_nes.h: galaga_nes.json - xxd -i $< | sed "s@unsigned@const@" > $@ - -clean: - rm -f test $(OBJ) smw_snes.h galaga_nes.h diff --git a/deps/rcheevos/test/galaga_nes.json b/deps/rcheevos/test/galaga_nes.json deleted file mode 100644 index 9039bec3b1..0000000000 --- a/deps/rcheevos/test/galaga_nes.json +++ /dev/null @@ -1,205 +0,0 @@ -{ - "Success": true, - "PatchData": { - "ID": 1701, - "Title": "Galaga", - "ConsoleID": 7, - "ForumTopicID": 2528, - "Flags": 0, - "ImageIcon": "\/Images\/002324.png", - "ImageTitle": "\/Images\/002322.png", - "ImageIngame": "\/Images\/002323.png", - "ImageBoxArt": "\/Images\/012173.png", - "Publisher": "Bandai America (NA), Namco (JP)", - "Developer": "Namco", - "Genre": "Fixed Shooter", - "Released": "Nov 1988 (NA), Feb 1985 (JP)", - "IsFinal": false, - "ConsoleName": "NES", - "RichPresencePatch": null, - "Achievements": [{ - "ID": 10055, - "MemAddr": "0xH0482=5", - "Title": "That Was Easy", - "Description": "Get to level 5.", - "Points": 5, - "Author": "dude1286", - "Modified": 1404761487, - "Created": 1404761423, - "BadgeName": "09723", - "Flags": 3 - }, { - "ID": 10056, - "MemAddr": "0xH0481=1", - "Title": "Getting Slightly Difficult", - "Description": "Get to level 10.", - "Points": 20, - "Author": "dude1286", - "Modified": 1404761490, - "Created": 1404761427, - "BadgeName": "09724", - "Flags": 3 - }, { - "ID": 10057, - "MemAddr": "0xH0481=2", - "Title": "Hail of Bullets", - "Description": "Get to level 20.", - "Points": 25, - "Author": "dude1286", - "Modified": 1404761493, - "Created": 1404761430, - "BadgeName": "09725", - "Flags": 3 - }, { - "ID": 10058, - "MemAddr": "0xH0481=3", - "Title": "Bulletstorm", - "Description": "Get to level 30.", - "Points": 40, - "Author": "dude1286", - "Modified": 1404761498, - "Created": 1404761435, - "BadgeName": "09726", - "Flags": 3 - }, { - "ID": 10059, - "MemAddr": "0xH0480=0_0xH0481=0_0xH0482=3_R:0xH0482!=3.1._0xH00c4=40", - "Title": "Challenge 1 Master", - "Description": "Get a perfect on Stage 3.", - "Points": 15, - "Author": "dude1286", - "Modified": 1404796406, - "Created": 1404761443, - "BadgeName": "09715", - "Flags": 3 - }, { - "ID": 10060, - "MemAddr": "0xH0480=0_0xH0481=0_0xH0482=7_0xH00c4=40_R:0xH0482!=7.1.", - "Title": "Challenge 2 Master", - "Description": "Get a perfect on Stage 7.", - "Points": 20, - "Author": "dude1286", - "Modified": 1404796449, - "Created": 1404761447, - "BadgeName": "09716", - "Flags": 3 - }, { - "ID": 10061, - "MemAddr": "0xH0480=0_0xH0481=1_0xH0482=1_R:0xH0482!=1.1._0xH00c4=40", - "Title": "Challenge 3 Master", - "Description": "Get a perfect on Stage 11.", - "Points": 25, - "Author": "dude1286", - "Modified": 1404796468, - "Created": 1404761450, - "BadgeName": "09717", - "Flags": 3 - }, { - "ID": 10062, - "MemAddr": "0xH0480=0_0xH0481=1_0xH0482=5_R:0xH0482!=5.1._0xH00c4=40", - "Title": "Challenge 4 Master", - "Description": "Get a perfect on Stage 15.", - "Points": 30, - "Author": "dude1286", - "Modified": 1404796484, - "Created": 1404761454, - "BadgeName": "09718", - "Flags": 3 - }, { - "ID": 10063, - "MemAddr": "0xH0480=0_0xH0481=1_0xH0482=9_R:0xH0482!=9.1._0xH00c4=40", - "Title": "Challenge 5 Master", - "Description": "Get a perfect on Stage 19.", - "Points": 35, - "Author": "dude1286", - "Modified": 1404796507, - "Created": 1404761457, - "BadgeName": "09719", - "Flags": 3 - }, { - "ID": 10064, - "MemAddr": "0xH0480=0_0xH0481=2_0xH0482=3_R:0xH0482!=3.1._0xH00c4=40", - "Title": "Challenge 6 Master", - "Description": "Get a perfect on Stage 23.", - "Points": 40, - "Author": "dude1286", - "Modified": 1404796523, - "Created": 1404761461, - "BadgeName": "09720", - "Flags": 3 - }, { - "ID": 10065, - "MemAddr": "0xH0480=0_0xH0481=2_0xH0482=7_R:0xH0482!=7.1._0xH00c4=40", - "Title": "Challenge 7 Master", - "Description": "Get a perfect on Stage 27.", - "Points": 45, - "Author": "dude1286", - "Modified": 1404796555, - "Created": 1404761464, - "BadgeName": "09721", - "Flags": 3 - }, { - "ID": 10066, - "MemAddr": "0xH0480=0_0xH0481=3_0xH0482=1_R:0xH0482!=1.1._0xH00c4=40", - "Title": "Challenge 8 Master", - "Description": "Get a perfect on Stage 31.", - "Points": 50, - "Author": "dude1286", - "Modified": 1404796574, - "Created": 1404761468, - "BadgeName": "09722", - "Flags": 3 - }, { - "ID": 10067, - "MemAddr": "0xH0079=4_d0xH0079=3", - "Title": "Was That On Purpose?", - "Description": "Get one of your ships captured by the enemy.", - "Points": 5, - "Author": "dude1286", - "Modified": 1404761532, - "Created": 1404761472, - "BadgeName": "09714", - "Flags": 3 - }, { - "ID": 10068, - "MemAddr": "d0xH0079=6_0xH0079=1", - "Title": "Doubled Fire", - "Description": "Save a captured ship and have double the fire power.", - "Points": 10, - "Author": "dude1286", - "Modified": 1404761536, - "Created": 1404761476, - "BadgeName": "09713", - "Flags": 3 - }, { - "ID": 10069, - "MemAddr": "0xH00e2>=3_d0xH00e2<3", - "Title": "Default Score", - "Description": "Get higher than the default hi-score.", - "Points": 10, - "Author": "dude1286", - "Modified": 1404761540, - "Created": 1404761479, - "BadgeName": "09727", - "Flags": 3 - }, { - "ID": 10070, - "MemAddr": "0xH0482=2_d0xH0482=1_0xH04af=0xH04a7_0xH04ae=0xH04a6_0xH04ad=0xH04a5", - "Title": "Perfect Shot", - "Description": "Get to the second level without missing a shot.", - "Points": 25, - "Author": "dude1286", - "Modified": 1404761543, - "Created": 1404761482, - "BadgeName": "09712", - "Flags": 3 - }], - "Leaderboards": [{ - "ID": 310, - "Mem": "STA:0xh0482=1::CAN:0xh0470=0_0xh0471=0::SUB:0xh0485=0_d0xh007a=0_0xh007a=1::VAL:0xh00e5*10_0xh00e4*100_0xh00e3*1000_0xh00e2*10000_0xh00e1*100000_0xh00e0*1000000", - "Format": "SCORE", - "Title": "Hi-Score", - "Description": "Get the highest score possible." - }] - } -} \ No newline at end of file diff --git a/deps/rcheevos/test/smw_snes.json b/deps/rcheevos/test/smw_snes.json deleted file mode 100644 index 767b526df8..0000000000 --- a/deps/rcheevos/test/smw_snes.json +++ /dev/null @@ -1,606 +0,0 @@ -{ - "Success": true, - "PatchData": { - "ID": 228, - "Title": "Super Mario World", - "ConsoleID": 3, - "ForumTopicID": 135, - "Flags": 0, - "ImageIcon": "\/Images\/006972.png", - "ImageTitle": "\/Images\/000021.png", - "ImageIngame": "\/Images\/000022.png", - "ImageBoxArt": "\/Images\/000138.png", - "Publisher": "Nintendo", - "Developer": "Nintendo EAD", - "Genre": "Platforming", - "Released": "JP 1990 , NA 1991 Europe 1992", - "IsFinal": false, - "ConsoleName": "SNES", - "RichPresencePatch": "Lookup:LevelName\r\n0x0=Title Screen\r\n0x14=Yellow Switch Palace\r\n0x28=Yoshi's House\r\n0x29=Yoshi's Island 1\r\n0x2a=Yoshi's Island 2\r\n0x27=Yoshi's Island 3\r\n0x26=Yoshi's Island 4\r\n0x25=#1 Iggy's Castle\r\n0x15=Donut Plains 1\r\n0x9=Donut Plains 2\r\n0x8=Green Switch Palace\r\n0x4=Donut Ghost House\r\n0x3=Top Secret Area\r\n0x5=Donut Plains 3\r\n0x6=Donut Plains 4\r\n0x7=#2 Morton's Castle\r\n0xa=Donut Secret 1\r\n0x13=Donut Secret House\r\n0x2f=Donut Secret 2\r\n0x3e=Vanilla Dome 1\r\n0x3c=Vanilla Dome 2\r\n0x3f=Red Switch Palace\r\n0x2b=Vanilla Ghost House\r\n0x2e=Vanilla Dome 3\r\n0x3d=Vanilla Dome 4\r\n0x40=#3 Lemmy's Castle\r\n0x2d=Vanilla Secret 1\r\n0x1=Vanilla Secret 2\r\n0x2=Vanilla Secret 3\r\n0xb=Vanilla Fortress\r\n0xc=Butter Bridge 1\r\n0xd=Butter Bridge 2\r\n0xe=#4 Ludwig's Castle\r\n0xf=Cheese Bridge Area\r\n0x10=Cookie Mountain\r\n0x11=Soda Lake\r\n0x41=Forest Ghost House\r\n0x42=Forest of Illusion 1\r\n0x43=Forest of Illusion 4\r\n0x44=Forest of Illusion 2\r\n0x45=Blue Switch Palace\r\n0x46=Forest Secret Area\r\n0x47=Forest of Illusion 3\r\n0x1f=Forest Fortress\r\n0x20=#5 Roy's Castle\r\n0x21=Choco-Ghost House\r\n0x22=Chocolate Island 1\r\n0x23=Chocolate Island 3\r\n0x24=Chocolate Island 2\r\n0x1b=Chocolate Fortress\r\n0x1d=Chocolate Island 4\r\n0x1c=Chocolate Island 5\r\n0x1a=#6 Wendy's Castle\r\n0x18=Sunken Ghost Ship\r\n0x3b=Chocolate Secret\r\n0x3a=Valley of Bowser 1\r\n0x39=Valley of Bowser 2\r\n0x38=Valley Ghost House\r\n0x37=Valley of Bowser 3\r\n0x33=Valley of Bowser 4\r\n0x34=#7 Larry's Castle\r\n0x35=Valley Fortress\r\n0x31=Front Door\r\n0x32=Back Door\r\n0x58=Star World 1\r\n0x54=Star World 2\r\n0x56=Star World 3\r\n0x59=Star World 4\r\n0x5a=Star World 5\r\n0x4e=Gnarly\r\n0x4f=Tubular\r\n0x50=Way Cool\r\n0x51=Awesome\r\n0x4c=Groovy\r\n0x4b=Mondo\r\n0x4a=Outrageous\r\n0x49=Funky\r\n\r\nFormat:Lives\r\nFormatType=VALUE\r\n\r\nDisplay:\r\n@LevelName(0xh0013bf), @Lives(0xh0dbe_v+1) lives", - "Achievements": [{ - "ID": 4874, - "MemAddr": "0xH000019=2", - "Title": "I Believe I Can Fly", - "Description": "Collect a feather", - "Points": 2, - "Author": "UNHchabo", - "Modified": 1452548368, - "Created": 1391908064, - "BadgeName": "05506", - "Flags": 3 - }, { - "ID": 4933, - "MemAddr": "0xH0018c2=1", - "Title": "Floating Through The Clouds", - "Description": "Hijack a Lakitu's cloud", - "Points": 2, - "Author": "UNHchabo", - "Modified": 1445779700, - "Created": 1392010935, - "BadgeName": "30357", - "Flags": 3 - }, { - "ID": 341, - "MemAddr": "0x001420=5", - "Title": "Unleash The Dragon", - "Description": "Collect 5 Dragon Coins in a level", - "Points": 3, - "Author": "Scott", - "Modified": 1445783661, - "Created": 1367266583, - "BadgeName": "00549", - "Flags": 3 - }, { - "ID": 342, - "MemAddr": "0xH000dc1=1_0xH0013bf>0", - "Title": "Giddy Up!", - "Description": "Catch a ride with a friend", - "Points": 2, - "Author": "Scott", - "Modified": 1445754183, - "Created": 1367266931, - "BadgeName": "00550", - "Flags": 3 - }, { - "ID": 340, - "MemAddr": "0xH000dbf=99", - "Title": "Rich Mario", - "Description": "Collect 99 coins", - "Points": 5, - "Author": "Scott", - "Modified": 1445757056, - "Created": 1367254976, - "BadgeName": "00547", - "Flags": 3 - }, { - "ID": 1706, - "MemAddr": "0xH001900=80", - "Title": "Maximum Finish", - "Description": "Cross the finish line at the end of the stage and collect the max 50 stars", - "Points": 10, - "Author": "jackolantern", - "Modified": 1372762549, - "Created": 1372674230, - "BadgeName": "02014", - "Flags": 3 - }, { - "ID": 2246, - "MemAddr": "0xH000f31=0.20._R:0xH000f31!=0_0xH000f32=0.20._R:0xH000f32!=0_0xH000f33=0.20._R:0xH000f33!=0_0xH000dbe>d0xH000dbe.8._0xH001411=1.20._R:0xH001411=0", - "Title": "Perfect Bonus Stage", - "Description": "Score 8 extra lives in the 'Bonus Game'", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445783578, - "Created": 1376582613, - "BadgeName": "02739", - "Flags": 3 - }, { - "ID": 2199, - "MemAddr": "0xH001f28=1_0xH001f27=1_0xH001f29=1_0xH001f2a=1", - "Title": "Filling All The Blocks In", - "Description": "Hit the buttons in all four coloured switch palaces", - "Points": 10, - "Author": "jackolantern", - "Modified": 1445756980, - "Created": 1376514114, - "BadgeName": "02720", - "Flags": 3 - }, { - "ID": 2253, - "MemAddr": "0xH0013bf=37_0xH000dd5=1", - "Title": "Iggy Koopa", - "Description": "Defeat Iggy Koopa of Castle #1", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445751693, - "Created": 1376616356, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 347, - "MemAddr": "0xH0013bf=7_0xH000dd5=1", - "Title": "Morton Koopa Jr.", - "Description": "Defeat Morton Koopa Jr. of Castle #2", - "Points": 5, - "Author": "Scott", - "Modified": 1445783647, - "Created": 1367322700, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2261, - "MemAddr": "0xH0013bf=64_0xH000dd5=1", - "Title": "Lemmy Koopa", - "Description": "Defeat Lemmy Koopa of Castle #3", - "Points": 10, - "Author": "Jaarl", - "Modified": 1425959153, - "Created": 1376652522, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2262, - "MemAddr": "0xH0013bf=14_0xH000dd5=1", - "Title": "Ludwig von Koopa", - "Description": "Defeat Ludwig von Koopa of Castle #4", - "Points": 10, - "Author": "Jaarl", - "Modified": 1425959133, - "Created": 1376653163, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2306, - "MemAddr": "0xH0013bf=32_0xH000dd5=1", - "Title": "Roy Koopa", - "Description": "Defeat Roy Koopa of Castle #5", - "Points": 10, - "Author": "Jaarl", - "Modified": 1425956637, - "Created": 1376938808, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2309, - "MemAddr": "0xH0013bf=26_0xH000906=1.400._R:0xH0013bf!=26", - "Title": "Wendy O. Koopa", - "Description": "Defeat Wendy O. Koopa of Castle #6", - "Points": 10, - "Author": "Jaarl", - "Modified": 1390938088, - "Created": 1376939582, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2342, - "MemAddr": "0xH0013bf=52_0xH000dd5=1", - "Title": "Larry Koopa", - "Description": "Defeat Larry Koopa of Castle #7", - "Points": 10, - "Author": "Jaarl", - "Modified": 1425959095, - "Created": 1376970283, - "BadgeName": "00562", - "Flags": 3 - }, { - "ID": 2250, - "MemAddr": "0xH0013bf=11(20)_0xH000906=1(20)_R:0xH001411!=1", - "Title": "Reznor", - "Description": "Defeat the Reznor atop Vanilla Dome", - "Points": 10, - "Author": "Jaarl", - "Modified": 1376615087, - "Created": 1376615073, - "BadgeName": "02742", - "Flags": 3 - }, { - "ID": 2307, - "MemAddr": "0xH0013bf=31(20)_0xH000906=1(20)_R:0xH001411!=1", - "Title": "Reznor Again?", - "Description": "Defeat the Reznor in the clearing of the Forest of Illusion", - "Points": 10, - "Author": "Jaarl", - "Modified": 1376938847, - "Created": 1376938811, - "BadgeName": "02742", - "Flags": 3 - }, { - "ID": 2308, - "MemAddr": "0xH0013bf=27.20._0xH000906=1.20._R:0xH001411!=1", - "Title": "Reznor, Do You Ever Give Up?", - "Description": "Defeat the Reznor at the center of Chocolate Island", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445751771, - "Created": 1376938815, - "BadgeName": "02742", - "Flags": 3 - }, { - "ID": 2338, - "MemAddr": "0xH0013bf=53.20._0xH000906=1.20._R:0xH001411!=1", - "Title": "Reznor...", - "Description": "Defeat the Reznor in the Valley of Bowser", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445783707, - "Created": 1376969412, - "BadgeName": "02742", - "Flags": 3 - }, { - "ID": 2275, - "MemAddr": "0xH0013bf=49_R:0xH0013bf!=49_0xH0013f9=3_R:0xH0013f9!=3_0xH0013ef=1_R:0xH0013ef!=1", - "Title": "King Bowser Koopa", - "Description": "Beat Bowser and save the princess (Front Door!)", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445783312, - "Created": 1376742802, - "BadgeName": "02764", - "Flags": 3 - }, { - "ID": 2276, - "MemAddr": "0xH0013bf=49_R:0xH0013bf!=49_0xH0013f9=3_R:0xH0013f9!=3_0xH0013ef=1_R:0xH0013ef!=1_0xH000019=0_R:0xH000019!=0", - "Title": "Baby's First Kiss", - "Description": "Get the princess kiss as Little Mario (Front Door!)", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445783313, - "Created": 1376742805, - "BadgeName": "02765", - "Flags": 3 - }, { - "ID": 2277, - "MemAddr": "0xH0013bf=49_R:0xH0013bf!=49_0xH0013f9=3_R:0xH0013f9!=3_0xH0013ef=1_R:0xH0013ef!=1_0xH000019=3_R:0xH000019!=3", - "Title": "Burning Bowser", - "Description": "Get the princess kiss as Fire Mario (Front Door!)", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445783314, - "Created": 1376742808, - "BadgeName": "02766", - "Flags": 3 - }, { - "ID": 2278, - "MemAddr": "0xH0013bf=49_R:0xH0013bf!=49_0xH0013f9=3_R:0xH0013f9!=3_0xH0013ef=1_R:0xH0013ef!=1_0xH000019=2_R:0xH000019!=2", - "Title": "Flying Finish", - "Description": "Get the princess kiss as Cape Mario (Front Door!)", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445783315, - "Created": 1376742811, - "BadgeName": "02767", - "Flags": 3 - }, { - "ID": 2299, - "MemAddr": "0xH000020=168_R:0xH000020!=168_0xH00001e=248_R:0xH00001e!=248_0xH0013c3=0_R:0xH0013c3!=0_0xH0013bf=19_R:0xH0013bf!=19_0xH001411=0", - "Title": "The Big Boo", - "Description": "Defeat the Big Boo in Donut Secret House", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445751707, - "Created": 1376918022, - "BadgeName": "02797", - "Flags": 3 - }, { - "ID": 2298, - "MemAddr": "0xH0013c3=6", - "Title": "To the Stars!", - "Description": "Reach the Star Road", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445751709, - "Created": 1376918019, - "BadgeName": "02798", - "Flags": 3 - }, { - "ID": 2264, - "MemAddr": "0xH0013c3=3_R:0xH0013c3!=3_0xH001411=0_0xH000007>112_0xH000007<128_0xH000008>112_0xH000008<128", - "Title": "I Could've Sworn...", - "Description": "Get lost in the Forest of Illusion", - "Points": 3, - "Author": "Jaarl", - "Modified": 1445751711, - "Created": 1376657732, - "BadgeName": "02753", - "Flags": 3 - }, { - "ID": 2305, - "MemAddr": "0xH00001e=169_0xH000020=28_0xH0013c3=0_0xH001411=0", - "Title": "Chocolate Donut", - "Description": "Walk in a circle on Chocolate Island", - "Points": 3, - "Author": "Jaarl", - "Modified": 1445754204, - "Created": 1376938805, - "BadgeName": "02806", - "Flags": 3 - }, { - "ID": 2300, - "MemAddr": "0xH0013c3=5", - "Title": "Mario's Special Place", - "Description": "Get to the challenging Special Zone", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445783441, - "Created": 1376918026, - "BadgeName": "02800", - "Flags": 3 - }, { - "ID": 2302, - "MemAddr": "0xH0013c3=5(1)_0xH0013c3=1(1)_R:0xH0013c3=6_R:0xH0013c3=0_R:0xH001f79=0", - "Title": "Change of Scenery", - "Description": "Clear the Special Zone and change the seasons in Mushroom Kingdom", - "Points": 10, - "Author": "Jaarl", - "Modified": 1376929315, - "Created": 1376929303, - "BadgeName": "02803", - "Flags": 3 - }, { - "ID": 2252, - "MemAddr": "0xH0013f3=1.20._0xH001411=1.20._R:0xH001411=0_0xH000019=0.20._R:0xH000019!=0.20.", - "Title": "Too Much Pasta", - "Description": "Let Little Mario load up on mama Luigi's Famous P(asta)-gas!", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445751717, - "Created": 1376615082, - "BadgeName": "02744", - "Flags": 3 - }, { - "ID": 2251, - "MemAddr": "0xH0013f3=1.20._0xH001411=1.20._R:0xH001411=0_0xH000019!=0_R:0xH000019=0", - "Title": "Another Kind of Flying", - "Description": "Send Mario flying with P-gas", - "Points": 5, - "Author": "Jaarl", - "Modified": 1445751754, - "Created": 1376615078, - "BadgeName": "02743", - "Flags": 3 - }, { - "ID": 2263, - "MemAddr": "0xH001697=12_0xH0013bf=66_R:0xH001697=0", - "Title": "Bother The Wigglers", - "Description": "Jump on yellow Wigglers in Forest of Illusion 12 times in a row for a surprise!", - "Points": 10, - "Author": "Jaarl", - "Modified": 1445751796, - "Created": 1376655155, - "BadgeName": "02752", - "Flags": 3 - }, { - "ID": 2274, - "MemAddr": "0xH0013bf=49_R:0xH0013bf!=49_0xH0013f9=3_R:0xH0013f9!=3_0xH001f2e=11_R:0xH001f2e!=11_0xH0013ef=1_R:0xH0013ef!=1", - "Title": "Shortest Route", - "Description": "Clear the fewest stages possible and beat the game", - "Points": 10, - "Author": "Jaarl", - "Modified": 1376742834, - "Created": 1376742799, - "BadgeName": "02768", - "Flags": 3 - }, { - "ID": 2297, - "MemAddr": "0xH001f2e=0.1._0xH001f2e=1.1._0xH001f2e=2.1._0xH001f2e=3.1._0xH001f2e=4.1._0xH001f2e=5.1._0xH001f2e=6.1._0xH001f2e=7.1._0xH001f2e=8.1._0xH001f2e=9.1._0xH001f2e=10.1._0xH001f2e=11.1._0xH0013f9=3_R:0xH000dbe -#include -#include - -#include "lua.h" -#include "lauxlib.h" - -typedef struct { - unsigned char* ram; - int size; -} -memory_t; - -static unsigned peekb(unsigned address, memory_t* memory) { - return address < memory->size ? memory->ram[address] : 0; -} - -static unsigned peek(unsigned address, unsigned num_bytes, void* ud) { - memory_t* memory = (memory_t*)ud; - - switch (num_bytes) { - case 1: return peekb(address, memory); - - case 2: return peekb(address, memory) | - peekb(address + 1, memory) << 8; - - case 4: return peekb(address, memory) | - peekb(address + 1, memory) << 8 | - peekb(address + 2, memory) << 16 | - peekb(address + 3, memory) << 24; - } - - return 0; -} - -static void parse_operand(rc_operand_t* self, const char** memaddr) { - int ret = rc_parse_operand(self, memaddr, 1, NULL, 0); - assert(ret >= 0); - assert(**memaddr == 0); - self->previous = 0; -} - -static void comp_operand(rc_operand_t* self, char expected_type, char expected_size, unsigned expected_value) { - assert(expected_type == self->type); - assert(expected_size == self->size); - assert(expected_value == self->value); -} - -static void parse_comp_operand(const char* memaddr, char expected_type, char expected_size, unsigned expected_value) { - rc_operand_t self; - int ret; - - ret = rc_parse_operand(&self, &memaddr, 1, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - comp_operand(&self, expected_type, expected_size, expected_value); -} - -static void parse_error_operand(const char* memaddr, int valid_chars) { - rc_operand_t self; - int ret; - const char* begin = memaddr; - - ret = rc_parse_operand(&self, &memaddr, 1, NULL, 0); - assert(ret < 0); - assert(memaddr - begin == valid_chars); -} - -static void parse_comp_operand_value(const char* memaddr, memory_t* memory, unsigned expected_value) { - rc_operand_t self; - unsigned value; - - rc_parse_operand(&self, &memaddr, 1, NULL, 0); - value = rc_evaluate_operand(&self, peek, memory, NULL); - - assert(value == expected_value); -} - -static void test_operand(void) { - { - /*------------------------------------------------------------------------ - TestParseVariableAddress - ------------------------------------------------------------------------*/ - - /* sizes */ - parse_comp_operand("0xH1234", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U); - parse_comp_operand("0x 1234", RC_OPERAND_ADDRESS, RC_OPERAND_16_BITS, 0x1234U); - parse_comp_operand("0x1234", RC_OPERAND_ADDRESS, RC_OPERAND_16_BITS, 0x1234U); - parse_comp_operand("0xW1234", RC_OPERAND_ADDRESS, RC_OPERAND_24_BITS, 0x1234U); - parse_comp_operand("0xX1234", RC_OPERAND_ADDRESS, RC_OPERAND_32_BITS, 0x1234U); - parse_comp_operand("0xL1234", RC_OPERAND_ADDRESS, RC_OPERAND_LOW, 0x1234U); - parse_comp_operand("0xU1234", RC_OPERAND_ADDRESS, RC_OPERAND_HIGH, 0x1234U); - parse_comp_operand("0xM1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_0, 0x1234U); - parse_comp_operand("0xN1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_1, 0x1234U); - parse_comp_operand("0xO1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_2, 0x1234U); - parse_comp_operand("0xP1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_3, 0x1234U); - parse_comp_operand("0xQ1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_4, 0x1234U); - parse_comp_operand("0xR1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_5, 0x1234U); - parse_comp_operand("0xS1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_6, 0x1234U); - parse_comp_operand("0xT1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_7, 0x1234U); - - /* sizes (ignore case) */ - parse_comp_operand("0Xh1234", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U); - parse_comp_operand("0xx1234", RC_OPERAND_ADDRESS, RC_OPERAND_32_BITS, 0x1234U); - parse_comp_operand("0xl1234", RC_OPERAND_ADDRESS, RC_OPERAND_LOW, 0x1234U); - parse_comp_operand("0xu1234", RC_OPERAND_ADDRESS, RC_OPERAND_HIGH, 0x1234U); - parse_comp_operand("0xm1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_0, 0x1234U); - parse_comp_operand("0xn1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_1, 0x1234U); - parse_comp_operand("0xo1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_2, 0x1234U); - parse_comp_operand("0xp1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_3, 0x1234U); - parse_comp_operand("0xq1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_4, 0x1234U); - parse_comp_operand("0xr1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_5, 0x1234U); - parse_comp_operand("0xs1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_6, 0x1234U); - parse_comp_operand("0xt1234", RC_OPERAND_ADDRESS, RC_OPERAND_BIT_7, 0x1234U); - - /* addresses */ - parse_comp_operand("0xH0000", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x0000U); - parse_comp_operand("0xH12345678", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x12345678U); - parse_comp_operand("0xHABCD", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0xABCDU); - parse_comp_operand("0xhabcd", RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0xABCDU); - } - - { - /*------------------------------------------------------------------------ - TestParseVariableDeltaMem - ------------------------------------------------------------------------*/ - - /* sizes */ - parse_comp_operand("d0xH1234", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0x1234U); - parse_comp_operand("d0x 1234", RC_OPERAND_DELTA, RC_OPERAND_16_BITS, 0x1234U); - parse_comp_operand("d0x1234", RC_OPERAND_DELTA, RC_OPERAND_16_BITS, 0x1234U); - parse_comp_operand("d0xW1234", RC_OPERAND_DELTA, RC_OPERAND_24_BITS, 0x1234U); - parse_comp_operand("d0xX1234", RC_OPERAND_DELTA, RC_OPERAND_32_BITS, 0x1234U); - parse_comp_operand("d0xL1234", RC_OPERAND_DELTA, RC_OPERAND_LOW, 0x1234U); - parse_comp_operand("d0xU1234", RC_OPERAND_DELTA, RC_OPERAND_HIGH, 0x1234U); - parse_comp_operand("d0xM1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_0, 0x1234U); - parse_comp_operand("d0xN1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_1, 0x1234U); - parse_comp_operand("d0xO1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_2, 0x1234U); - parse_comp_operand("d0xP1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_3, 0x1234U); - parse_comp_operand("d0xQ1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_4, 0x1234U); - parse_comp_operand("d0xR1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_5, 0x1234U); - parse_comp_operand("d0xS1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_6, 0x1234U); - parse_comp_operand("d0xT1234", RC_OPERAND_DELTA, RC_OPERAND_BIT_7, 0x1234U); - - /* ignores case */ - parse_comp_operand("D0Xh1234", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0x1234U); - - /* addresses */ - parse_comp_operand("d0xH0000", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0x0000U); - parse_comp_operand("d0xH12345678", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0x12345678U); - parse_comp_operand("d0xHABCD", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0xABCDU); - parse_comp_operand("d0xhabcd", RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0xABCDU); - } - - { - /*------------------------------------------------------------------------ - TestParseVariableValue - ------------------------------------------------------------------------*/ - - /* decimal - values don't actually have size, default is RC_OPERAND_8_BITS */ - parse_comp_operand("123", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 123U); - parse_comp_operand("123456", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 123456U); - parse_comp_operand("0", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0U); - parse_comp_operand("0000000000", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0U); - parse_comp_operand("4294967295", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 4294967295U); - - /* hex - 'H' prefix, not '0x'! */ - parse_comp_operand("H123", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0x123U); - parse_comp_operand("HABCD", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0xABCDU); - parse_comp_operand("h123", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0x123U); - parse_comp_operand("habcd", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 0xABCDU); - parse_comp_operand("HFFFFFFFF", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 4294967295U); - - /* '0x' is an address */ - parse_comp_operand("0x123", RC_OPERAND_ADDRESS, RC_OPERAND_16_BITS, 0x123U); - - /* hex without prefix */ - parse_error_operand("ABCD", 0); - - /* more than 32-bits (error), will be constrained to 32-bits */ - parse_comp_operand("4294967296", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 4294967295U); - - /* negative value (error), will be "wrapped around": -1 = 0x100000000 - 1 = 0xFFFFFFFF = 4294967295 */ - parse_comp_operand("-1", RC_OPERAND_CONST, RC_OPERAND_8_BITS, 4294967295U); - } - - { - /*------------------------------------------------------------------------ - TestVariableGetValue - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - memory.ram = ram; - memory.size = sizeof(ram); - - /* value */ - parse_comp_operand_value("0", &memory, 0x00U); - - /* eight-bit */ - parse_comp_operand_value("0xh0", &memory, 0x00U); - parse_comp_operand_value("0xh1", &memory, 0x12U); - parse_comp_operand_value("0xh4", &memory, 0x56U); - parse_comp_operand_value("0xh5", &memory, 0x00U); /* out of range */ - - /* sixteen-bit */ - parse_comp_operand_value("0x 0", &memory, 0x1200U); - parse_comp_operand_value("0x 3", &memory, 0x56ABU); - parse_comp_operand_value("0x 4", &memory, 0x0056U); /* out of range */ - - /* thirty-two-bit */ - parse_comp_operand_value("0xx0", &memory, 0xAB341200U); - parse_comp_operand_value("0xx1", &memory, 0x56AB3412U); - parse_comp_operand_value("0xx3", &memory, 0x000056ABU); /* out of range */ - - /* nibbles */ - parse_comp_operand_value("0xu0", &memory, 0x0U); - parse_comp_operand_value("0xu1", &memory, 0x1U); - parse_comp_operand_value("0xu4", &memory, 0x5U); - parse_comp_operand_value("0xu5", &memory, 0x0U); /* out of range */ - - parse_comp_operand_value("0xl0", &memory, 0x0U); - parse_comp_operand_value("0xl1", &memory, 0x2U); - parse_comp_operand_value("0xl4", &memory, 0x6U); - parse_comp_operand_value("0xl5", &memory, 0x0U); /* out of range */ - - /* bits */ - parse_comp_operand_value("0xm0", &memory, 0x0U); - parse_comp_operand_value("0xm3", &memory, 0x1U); - parse_comp_operand_value("0xn3", &memory, 0x1U); - parse_comp_operand_value("0xo3", &memory, 0x0U); - parse_comp_operand_value("0xp3", &memory, 0x1U); - parse_comp_operand_value("0xq3", &memory, 0x0U); - parse_comp_operand_value("0xr3", &memory, 0x1U); - parse_comp_operand_value("0xs3", &memory, 0x0U); - parse_comp_operand_value("0xt3", &memory, 0x1U); - parse_comp_operand_value("0xm5", &memory, 0x0U); /* out of range */ - } - - { - /*------------------------------------------------------------------------ - TestVariableGetValueDelta - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_operand_t op; - const char* memaddr; - - memory.ram = ram; - memory.size = sizeof(ram); - - memaddr = "d0xh1"; - parse_operand(&op, &memaddr); - - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x00); /* first call gets uninitialized value */ - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x12); /* second gets current value */ - - /* RC_OPERAND_DELTA is always one frame behind */ - ram[1] = 0x13; - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x12U); - - ram[1] = 0x14; - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x13U); - - ram[1] = 0x15; - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x14U); - - ram[1] = 0x16; - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x15U); - - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x16U); - assert(rc_evaluate_operand(&op, peek, &memory, NULL) == 0x16U); - } -} - -static void parse_condition(rc_condition_t* self, const char* memaddr) { - int ret; - rc_scratch_t scratch; - - ret = 0; - rc_parse_condition(&ret, self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); -} - -static void parse_comp_condition( - const char* memaddr, char expected_type, - char expected_left_type, char expected_left_size, unsigned expected_left_value, - char expected_operator, - char expected_right_type, char expected_right_size, unsigned expected_right_value, - int expected_required_hits -) { - rc_condition_t self; - parse_condition(&self, memaddr); - - assert(self.type == expected_type); - comp_operand(&self.operand1, expected_left_type, expected_left_size, expected_left_value); - assert(self.oper == expected_operator); - comp_operand(&self.operand2, expected_right_type, expected_right_size, expected_right_value); - assert(self.required_hits == expected_required_hits); -} - -static void parse_test_condition(const char* memaddr, memory_t* memory, int value) { - rc_condition_t self; - int ret; - rc_scratch_t scratch; - - ret = 0; - rc_parse_condition(&ret, &self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - ret = rc_test_condition(&self, 0, peek, memory, NULL); - - assert((ret && value) || (!ret && !value)); -} - -static void test_condition(void) { - { - /*------------------------------------------------------------------------ - TestParseConditionMemoryComparisonValue - ------------------------------------------------------------------------*/ - - /* different comparisons */ - parse_comp_condition( - "0xH1234=8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234==8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234!=8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_NE, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234<8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_LT, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234<=8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_LE, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234>8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_GT, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "0xH1234>=8", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_GE, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - /* delta */ - parse_comp_condition( - "d0xH1234=8", - RC_CONDITION_STANDARD, - RC_OPERAND_DELTA, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - /* flags */ - parse_comp_condition( - "R:0xH1234=8", - RC_CONDITION_RESET_IF, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "P:0xH1234=8", - RC_CONDITION_PAUSE_IF, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "A:0xH1234=8", - RC_CONDITION_ADD_SOURCE, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "B:0xH1234=8", - RC_CONDITION_SUB_SOURCE, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - parse_comp_condition( - "C:0xH1234=8", - RC_CONDITION_ADD_HITS, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 0 - ); - - /* hit count */ - parse_comp_condition( - "0xH1234=8(1)", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 1 - ); - - parse_comp_condition( - "0xH1234=8.1.", /* legacy format */ - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 1 - ); - - parse_comp_condition( - "0xH1234=8(100)", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_CONST, RC_OPERAND_8_BITS, 8U, - 100 - ); - } - - { - /*------------------------------------------------------------------------ - TestParseConditionMemoryComparisonHexValue - ------------------------------------------------------------------------*/ - - /* hex value is interpreted as a 16-bit memory reference */ - parse_comp_condition( - "0xH1234=0x80", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_8_BITS, 0x1234U, - RC_CONDITION_EQ, - RC_OPERAND_ADDRESS, RC_OPERAND_16_BITS, 0x80U, - 0 - ); - } - - { - /*------------------------------------------------------------------------ - TestParseConditionMemoryComparisonMemory - ------------------------------------------------------------------------*/ - - parse_comp_condition( - "0xL1234!=0xU3456", - RC_CONDITION_STANDARD, - RC_OPERAND_ADDRESS, RC_OPERAND_LOW, 0x1234U, - RC_CONDITION_NE, - RC_OPERAND_ADDRESS, RC_OPERAND_HIGH, 0x3456U, - 0 - ); - } - - { - /*------------------------------------------------------------------------ - TestConditionCompare - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - - memory.ram = ram; - memory.size = sizeof(ram); - - /* values */ - parse_test_condition("0xH0001=18", &memory, 1); - parse_test_condition("0xH0001!=18", &memory, 0); - parse_test_condition("0xH0001<=18", &memory, 1); - parse_test_condition("0xH0001>=18", &memory, 1); - parse_test_condition("0xH0001<18", &memory, 0); - parse_test_condition("0xH0001>18", &memory, 0); - parse_test_condition("0xH0001>0", &memory, 1); - parse_test_condition("0xH0001!=0", &memory, 1); - - /* memory */ - parse_test_condition("0xH0001<0xH0002", &memory, 1); - parse_test_condition("0xH0001>0xH0002", &memory, 0); - parse_test_condition("0xH0001=0xH0001", &memory, 1); - parse_test_condition("0xH0001!=0xH0002", &memory, 1); - } - - { - /*------------------------------------------------------------------------ - TestConditionCompareDelta - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_condition_t cond; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_condition(&cond, "0xH0001>d0xH0001"); - - /* initial delta value is 0, 0x12 > 0 */ - assert(rc_test_condition(&cond, 0, peek, &memory, NULL) == 1); - - /* delta value is now 0x12, 0x12 = 0x12 */ - assert(rc_test_condition(&cond, 0, peek, &memory, NULL) == 0); - - /* delta value is now 0x12, 0x11 < 0x12 */ - ram[1] = 0x11; - assert(rc_test_condition(&cond, 0, peek, &memory, NULL) == 0); - - /* delta value is now 0x13, 0x12 > 0x11 */ - ram[1] = 0x12; - assert(rc_test_condition(&cond, 0, peek, &memory, NULL) == 1); - } -} - -static void parse_trigger(rc_trigger_t** self, void* buffer, const char* memaddr) { - assert(rc_trigger_size(memaddr) >= 0); - *self = rc_parse_trigger(buffer, memaddr, NULL, 0); - assert(*self != NULL); -} - -static void comp_trigger(rc_trigger_t* self, memory_t* memory, int expected_result) { - int ret = rc_test_trigger(self, peek, memory, NULL); - assert(expected_result == ret); -} - -static rc_condition_t* condset_get_cond(rc_condset_t* condset, int ndx) { - rc_condition_t* cond = condset->conditions; - - while (ndx-- != 0) { - assert(cond != NULL); - cond = cond->next; - } - - assert(cond != NULL); - return cond; -} - -static rc_condset_t* trigger_get_set(rc_trigger_t* trigger, int ndx) { - rc_condset_t* condset = trigger->alternative; - - if (ndx-- == 0) { - assert(trigger->requirement != NULL); - return trigger->requirement; - } - - while (ndx-- != 0) { - condset = condset->next; - assert(condset != NULL); - } - - assert(condset != NULL); - return condset; -} - -static void test_trigger(void) { - { - /*------------------------------------------------------------------------ - TestSimpleSets - Only standard conditions, no alt groups - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18"); /* one condition, true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - - parse_trigger(&trigger, buffer, "0xH0001!=18"); /* one condition, false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - - parse_trigger(&trigger, buffer, "0xH0001=18_0xH0002=52"); /* two conditions, true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - parse_trigger(&trigger, buffer, "0xH0001=18_0xH0002>52"); /* two conditions, false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - - parse_trigger(&trigger, buffer, "0xH0001=18_0xH0002=52_0xL0004=6"); /* three conditions, true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - parse_trigger(&trigger, buffer, "0xH0001=16_0xH0002=52_0xL0004=6"); /* three conditions, first false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - parse_trigger(&trigger, buffer, "0xH0001=18_0xH0002=50_0xL0004=6"); /* three conditions, first false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - parse_trigger(&trigger, buffer, "0xH0001=18_0xH0002=52_0xL0004=4"); /* three conditions, first false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - - parse_trigger(&trigger, buffer, "0xH0001=16_0xH0002=50_0xL0004=4"); /* three conditions, all false */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - } - - { - /*------------------------------------------------------------------------ - TestPauseIf - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_P:0xH0002=52_P:0xL0x0004=6"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* Also true, but processing stops on first PauseIf */ - - ram[2] = 0; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* PauseIf goes to 0 when false */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); /* PauseIf stays at 1 when false */ - - ram[4] = 0; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* PauseIf goes to 0 when false */ - } - - { - /*------------------------------------------------------------------------ - TestPauseIfHitCountOne - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_P:0xH0002=52.1."); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[2] = 0; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); /* PauseIf with HitCount doesn't automatically go back to 0 */ - } - - { - /*------------------------------------------------------------------------ - TestPauseIfHitCountTwo - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_P:0xH0002=52.2."); - comp_trigger(trigger, &memory, 1); /* PauseIf counter hasn't reached HitCount target, non-PauseIf condition still true */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - comp_trigger(trigger, &memory, 0); /* PauseIf counter has reached HitCount target, non-PauseIf conditions ignored */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - ram[2] = 0; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); /* PauseIf with HitCount doesn't automatically go back to 0 */ - } - - { - /*------------------------------------------------------------------------ - TestPauseIfHitReset - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_P:0xH0002=52.1._R:0xH0003=1SR:0xH0003=2"); - comp_trigger(trigger, &memory, 0); /* Trigger PauseIf, non-PauseIf conditions ignored */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - - ram[2] = 0; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); /* PauseIf with HitCount doesn't automatically go back to 0 */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - - ram[3] = 1; - comp_trigger(trigger, &memory, 0); /* ResetIf in Paused group is ignored */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - - ram[3] = 2; - comp_trigger(trigger, &memory, 0); /* ResetIf in alternate group is honored, PauseIf does not retrigger and non-PauseIf condition is true */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* ResetIf causes entire achievement to fail */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - - ram[3] = 3; - comp_trigger(trigger, &memory, 1); /* ResetIf no longer true, achievement allowed to trigger */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - } - - { - /*------------------------------------------------------------------------ - TestResetIf - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_R:0xH0002=50_R:0xL0x0004=4"); - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - - ram[2] = 50; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* True, but ResetIf also resets true marker */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - - ram[4] = 0x54; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* True, but ResetIf also resets true marker */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* Also true, but processing stop on first ResetIf */ - - ram[2] = 52; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* True, but ResetIf also resets true marker */ - - ram[4] = 0x56; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - } - - { - /*------------------------------------------------------------------------ - TestHitCount - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=20(2)_0xH0002=52"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[1] = 20; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); /* hits stop increment once count it reached */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 4U); - } - - { - /*------------------------------------------------------------------------ - TestHitCountResetIf - Verifies that ResetIf resets HitCounts - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(2)_0xH0002=52_R:0xL0004=4"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - - ram[4] = 0x54; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - - ram[4] = 0x56; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - } - - { - /*------------------------------------------------------------------------ - TestHitCountResetIfHitCount - Verifies that ResetIf with HitCount target only resets HitCounts when target is met - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(2)_0xH0002=52_R:0xL0004=4.2."); - comp_trigger(trigger, &memory, 0); /* HitCounts on conditions 1 and 2 are incremented */ - comp_trigger(trigger, &memory, 1); /* HitCounts on conditions 1 and 2 are incremented, cond 1 is now true so entire achievement is true */ - comp_trigger(trigger, &memory, 1); /* HitCount on condition 2 is incremented, cond 1 already met its target HitCount */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* ResetIf HitCount should still be 0 */ - - ram[4] = 0x54; - - /* first hit on ResetIf should not reset anything */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); /* condition 1 stopped at it's HitCount target */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 4U); /* condition 2 continues to increment */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); /* ResetIf HitCount should be 1 */ - - /* second hit on ResetIf should reset everything */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* ResetIf HitCount should also be reset */ - } - - { - /*------------------------------------------------------------------------ - TestAddHitsResetIf - Verifies that ResetIf works with AddHits - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "C:0xH0001=18_R:0xL0004=6(3)"); /* never(repeated(3, byte(1) == 18 || low(4) == 6)) */ - comp_trigger(trigger, &memory, 1); /* result is true, no non-reset conditions */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - comp_trigger(trigger, &memory, 0); /* total hits met (2 for each condition, only needed 3 total) (2 hits on condition 2 is not enough), result is always false if reset */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - } - - { - /*------------------------------------------------------------------------ - TestHitCountResetIfHitCountOne - Verifies that ResetIf HitCount(1) behaves like ResetIf without a HitCount - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(2)_0xH0002=52_R:0xL0004=4.1."); - comp_trigger(trigger, &memory, 0); /* HitCounts on conditions 1 and 2 are incremented */ - comp_trigger(trigger, &memory, 1); /* HitCounts on conditions 1 and 2 are incremented, cond 1 is now true so entire achievement is true */ - comp_trigger(trigger, &memory, 1); /* HitCount on condition 2 is incremented, cond 1 already met its target HitCount */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* ResetIf HitCount should still be 0 */ - - ram[4] = 0x54; - - /* ResetIf HitCount(1) should behave just like ResetIf without a HitCount - all items, including ResetIf should be reset. */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); /* ResetIf HitCount should also be reset */ - } - - { - /*------------------------------------------------------------------------ - TestHitCountPauseIf - Verifies that PauseIf stops HitCount processing - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(2)_0xH0002=52_P:0xL0004=4"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[4] = 0x54; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[4] = 0x56; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - ram[4] = 0x54; - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - ram[4] = 0x56; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - } - - { - /*------------------------------------------------------------------------ - TestHitCountPauseIfResetIf - Verifies that PauseIf prevents ResetIf processing - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(2)_R:0xH0002=50_P:0xL0004=4"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[4] = 0x54; /* pause */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[2] = 50; /* reset (but still paused) */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[4] = 0x56; /* unpause (still reset) */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - - ram[2] = 52; /* unreset */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - } - - { - /*------------------------------------------------------------------------ - TestAddSource - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "A:0xH0001=0_0xH0002=22"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - - ram[2] = 4; /* sum is correct */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[1] = 0; /* first condition is true, but not sum */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[2] = 22; /* first condition is true, sum is correct */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - } - - { - /*------------------------------------------------------------------------ - TestSubSource - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "B:0xH0002=0_0xH0001=14"); /* NOTE: SubSource subtracts the first value from the second! */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - - ram[2] = 4; /* difference is correct */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[1] = 0; /* first condition is true, but not difference */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[2] = 14; /* first condition is true, value is negative inverse of expected value */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[1] = 28; /* difference is correct again */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - } - - { - /*------------------------------------------------------------------------ - TestAddSubSource - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "A:0xH0001=0_B:0xL0002=0_0xL0004=14"); /* byte(1) - low(2) + low(4) == 14 */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 0U); - - ram[1] = 12; /* total is correct */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - ram[1] = 0; /* first condition is true, but not total */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - ram[4] = 18; /* byte(4) would make total true, but not low(4) */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 1U); - - ram[2] = 1; - ram[4] = 15; /* difference is correct again */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); /* AddSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 0U); /* SubSource condition does not have hit tracking */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 2)->current_hits == 2U); - } - - { - /*------------------------------------------------------------------------ - TestAddHits - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - rc_condset_t* condset; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "C:0xH0001=18(2)_0xL0004=6(4)"); /* repeated(4, byte(1) == 18 || low(4) == 6) */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - comp_trigger(trigger, &memory, 1); /* total hits met (2 for each condition) */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); /* threshold met, stop incrementing */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); /* total met prevents incrementing even though individual tally has not reached total */ - - rc_reset_condset(trigger->requirement); - - for (condset = trigger->alternative; condset != NULL; condset = condset->next) { - rc_reset_condset(condset); - } - - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 1U); - - ram[1] = 16; - comp_trigger(trigger, &memory, 0); /* 1 + 2 < 4, not met */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 2U); - - comp_trigger(trigger, &memory, 1); /* 1 + 3 = 4, met */ - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 0), 1)->current_hits == 3U); - } - - { - /*------------------------------------------------------------------------ - TestAltGroups - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=16S0xH0002=52S0xL0004=6"); - - /* core not true, both alts are */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 1U); - - ram[1] = 16; /* core and both alts true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 2U); - - ram[4] = 0; /* core and first alt true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 2U); - - ram[2] = 0; /* core true, but neither alt is */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 2U); - - ram[4] = 6; /* core and second alt true */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 4U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 3U); - } - - { - /*------------------------------------------------------------------------ - TestResetIfInAltGroup - Verifies that a ResetIf resets everything regardless of where it is - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18(1)_R:0xH0000=1S0xH0002=52(1)S0xL0004=6(1)_R:0xH0000=2"); - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 1U); - - ram[0] = 1; /* reset in core group resets everything */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 0U); - - ram[0] = 0; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 1U); - - ram[0] = 2; /* reset in alt group resets everything */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 0U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 0U); - } - - { - /*------------------------------------------------------------------------ - TestPauseIfInAltGroup - Verifies that PauseIf only pauses the group it's in - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0001=18_P:0xH0000=1S0xH0002=52S0xL0004=6_P:0xH0000=2"); - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 1U); - - ram[0] = 1; /* pause in core group only pauses core group */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 2U); - - ram[0] = 0; - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 2U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 3U); - - ram[0] = 2; /* pause in alt group only pauses alt group */ - comp_trigger(trigger, &memory, 1); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 3U); - assert(condset_get_cond(trigger_get_set(trigger, 1), 0)->current_hits == 4U); - assert(condset_get_cond(trigger_get_set(trigger, 2), 0)->current_hits == 3U); - } - - { - /*------------------------------------------------------------------------ - TestPauseIfResetIfAltGroup - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_trigger(&trigger, buffer, "0xH0000=0.1._0xH0000=2SP:0xH0001=18_R:0xH0002=52"); - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[0] = 1; /* move off HitCount */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[1] = 16; /* unpause alt group, HitCount should be reset */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 0U); - - ram[0] = 0; - ram[1] = 18; /* repause alt group, reset hitcount target, hitcount should be set */ - comp_trigger(trigger, &memory, 0); - assert(condset_get_cond(trigger_get_set(trigger, 0), 0)->current_hits == 1U); - - ram[0] = 2; /* trigger win condition. alt group has no normal conditions, it should be considered false */ - comp_trigger(trigger, &memory, 0); - } -} - -static void parse_comp_term(const char* memaddr, char expected_var_size, unsigned expected_address, int is_bcd, int is_const) { - rc_term_t self; - rc_scratch_t scratch; - int ret; - - ret = 0; - rc_parse_term(&ret, &self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - assert(is_const || self.operand1.size == expected_var_size); - assert(self.operand1.value == expected_address); - assert(self.operand1.is_bcd == is_bcd); - assert(self.invert == 0); - assert(self.operand2.size == RC_OPERAND_8_BITS); - assert(self.operand2.value == 0U); - assert(!is_const || self.operand1.type == RC_OPERAND_CONST); -} - -static void parse_comp_term_fp(const char* memaddr, char expected_var_size, unsigned expected_address, double fp) { - rc_term_t self; - rc_scratch_t scratch; - int ret; - - ret = 0; - rc_parse_term(&ret, &self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - assert(self.operand1.size == expected_var_size); - assert(self.operand1.value == expected_address); - assert(self.operand2.type == RC_OPERAND_FP); - assert(self.operand2.fp_value == fp); -} - -static void parse_comp_term_mem(const char* memaddr, char expected_size_1, unsigned expected_address_1, char expected_size_2, unsigned expected_address_2) { - rc_term_t self; - rc_scratch_t scratch; - int ret; - - ret = 0; - rc_parse_term(&ret, &self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - assert(self.operand1.size == expected_size_1); - assert(self.operand1.value == expected_address_1); - assert(self.operand2.size == expected_size_2); - assert(self.operand2.value == expected_address_2); -} - -static void parse_comp_term_value(const char* memaddr, memory_t* memory, unsigned value) { - rc_term_t self; - rc_scratch_t scratch; - int ret; - - ret = 0; - rc_parse_term(&ret, &self, &scratch, &memaddr, NULL, 0); - assert(ret >= 0); - assert(*memaddr == 0); - - assert(rc_evaluate_term(&self, peek, memory, NULL) == value); -} - -static void test_term(void) { - { - /*------------------------------------------------------------------------ - TestClauseParseFromString - ------------------------------------------------------------------------*/ - - /* sizes */ - parse_comp_term("0xH1234", RC_OPERAND_8_BITS, 0x1234U, 0, 0); - parse_comp_term("0x 1234", RC_OPERAND_16_BITS, 0x1234U, 0, 0); - parse_comp_term("0x1234", RC_OPERAND_16_BITS, 0x1234U, 0, 0); - parse_comp_term("0xW1234", RC_OPERAND_24_BITS, 0x1234U, 0, 0); - parse_comp_term("0xX1234", RC_OPERAND_32_BITS, 0x1234U, 0, 0); - parse_comp_term("0xL1234", RC_OPERAND_LOW, 0x1234U, 0, 0); - parse_comp_term("0xU1234", RC_OPERAND_HIGH, 0x1234U, 0, 0); - parse_comp_term("0xM1234", RC_OPERAND_BIT_0, 0x1234U, 0, 0); - parse_comp_term("0xN1234", RC_OPERAND_BIT_1, 0x1234U, 0, 0); - parse_comp_term("0xO1234", RC_OPERAND_BIT_2, 0x1234U, 0, 0); - parse_comp_term("0xP1234", RC_OPERAND_BIT_3, 0x1234U, 0, 0); - parse_comp_term("0xQ1234", RC_OPERAND_BIT_4, 0x1234U, 0, 0); - parse_comp_term("0xR1234", RC_OPERAND_BIT_5, 0x1234U, 0, 0); - parse_comp_term("0xS1234", RC_OPERAND_BIT_6, 0x1234U, 0, 0); - parse_comp_term("0xT1234", RC_OPERAND_BIT_7, 0x1234U, 0, 0); - - /* BCD */ - parse_comp_term("B0xH1234", RC_OPERAND_8_BITS, 0x1234U, 1, 0); - parse_comp_term("B0xX1234", RC_OPERAND_32_BITS, 0x1234U, 1, 0); - parse_comp_term("b0xH1234", RC_OPERAND_8_BITS, 0x1234U, 1, 0); - - /* Value */ - parse_comp_term("V1234", 0, 1234, 0, 1); - parse_comp_term("V+1", 0, 1, 0, 1); - parse_comp_term("V-1", 0, 0xFFFFFFFFU, 0, 1); - parse_comp_term("V-2", 0, 0xFFFFFFFEU, 0, 1); /* twos compliment still works for addition */ - } - - { - /*------------------------------------------------------------------------ - TestClauseParseFromStringMultiply - ------------------------------------------------------------------------*/ - - parse_comp_term_fp("0xH1234", RC_OPERAND_8_BITS, 0x1234U, 1.0); - parse_comp_term_fp("0xH1234*1", RC_OPERAND_8_BITS, 0x1234U, 1.0); - parse_comp_term_fp("0xH1234*3", RC_OPERAND_8_BITS, 0x1234U, 3.0); - parse_comp_term_fp("0xH1234*0.5", RC_OPERAND_8_BITS, 0x1234U, 0.5); - parse_comp_term_fp("0xH1234*-1", RC_OPERAND_8_BITS, 0x1234U, -1.0); - } - - { - /*------------------------------------------------------------------------ - TestClauseParseFromStringMultiplyAddress - ------------------------------------------------------------------------*/ - - parse_comp_term_mem("0xH1234", RC_OPERAND_8_BITS, 0x1234U, RC_OPERAND_8_BITS, 0U); - parse_comp_term_mem("0xH1234*0xH3456", RC_OPERAND_8_BITS, 0x1234U, RC_OPERAND_8_BITS, 0x3456U); - parse_comp_term_mem("0xH1234*0xL2222", RC_OPERAND_8_BITS, 0x1234U, RC_OPERAND_LOW, 0x2222U); - parse_comp_term_mem("0xH1234*0x1111", RC_OPERAND_8_BITS, 0x1234U, RC_OPERAND_16_BITS, 0x1111U); - } - - { - /*------------------------------------------------------------------------ - TestClauseGetValue - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - - memory.ram = ram; - memory.size = sizeof(ram); - - /* value */ - parse_comp_term_value("V6", &memory, 6); - parse_comp_term_value("V6*2", &memory, 12); - parse_comp_term_value("V6*0.5", &memory, 3); - - /* memory */ - parse_comp_term_value("0xH01", &memory, 0x12); - parse_comp_term_value("0x0001", &memory, 0x3412); - - /* BCD encoding */ - parse_comp_term_value("B0xH01", &memory, 12); - parse_comp_term_value("B0x0001", &memory, 3412); - - /* multiplication */ - parse_comp_term_value("0xH01*4", &memory, 0x12 * 4); /* multiply by constant */ - parse_comp_term_value("0xH01*0.5", &memory, 0x12 / 2); /* multiply by fraction */ - parse_comp_term_value("0xH01*0xH02", &memory, 0x12 * 0x34); /* multiply by second address */ - parse_comp_term_value("0xH01*0xT02", &memory, 0); /* multiply by bit */ - parse_comp_term_value("0xH01*~0xT02", &memory, 0x12); /* multiply by inverse bit */ - parse_comp_term_value("0xH01*~0xH02", &memory, 0x12 * (0x34 ^ 0xff)); /* multiply by inverse byte */ - } -} - -static void parse_comp_value(const char* memaddr, memory_t* memory, unsigned expected_value) { - rc_value_t* self; - char buffer[2048]; - int ret; - - ret = rc_value_size(memaddr); - assert(ret >= 0); - - self = rc_parse_value(buffer, memaddr, NULL, 0); - assert(self != NULL); - - assert(rc_evaluate_value(self, peek, memory, NULL) == expected_value); -} - -static void test_value(void) { - { - /*------------------------------------------------------------------------ - TestAdditionSimple - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - - memory.ram = ram; - memory.size = sizeof(ram); - - parse_comp_value("0xH0001_0xH0002", &memory, 0x12U + 0x34U); /* TestAdditionSimple */ - parse_comp_value("0xH0001*100_0xH0002*0.5_0xL0003", &memory, 0x12U * 100 + 0x34U / 2 + 0x0B);/* TestAdditionComplex */ - parse_comp_value("0xH0001$0xH0002", &memory, 0x34U);/* TestMaximumSimple */ - parse_comp_value("0xH0001_0xH0004*3$0xH0002*0xL0003", &memory, 0x34U * 0xBU);/* TestMaximumComplex */ - } - - { - /*------------------------------------------------------------------------ - TestFormatValue - ------------------------------------------------------------------------*/ - - char buffer[64]; - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_VALUE); - assert(!strcmp("12345", buffer)); - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_OTHER); - assert(!strcmp("012345", buffer)); - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_SCORE); - assert(!strcmp("012345 Points", buffer)); - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_SECONDS); - assert(!strcmp("205:45", buffer)); - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_CENTISECS); - assert(!strcmp("02:03.45", buffer)); - - rc_format_value(buffer, sizeof(buffer), 12345, RC_FORMAT_FRAMES); - assert(!strcmp("03:25.75", buffer)); - - rc_format_value(buffer, sizeof(buffer), 345, RC_FORMAT_SECONDS); - assert(!strcmp("05:45", buffer)); - - rc_format_value(buffer, sizeof(buffer), 345, RC_FORMAT_CENTISECS); - assert(!strcmp("00:03.45", buffer)); - - rc_format_value(buffer, sizeof(buffer), 345, RC_FORMAT_FRAMES); - assert(!strcmp("00:05.75", buffer)); - } - - { - /*------------------------------------------------------------------------ - TestParseMemValueFormat - ------------------------------------------------------------------------*/ - - assert(rc_parse_format("VALUE") == RC_FORMAT_VALUE); - assert(rc_parse_format("SECS") == RC_FORMAT_SECONDS); - assert(rc_parse_format("TIMESECS") == RC_FORMAT_SECONDS); - assert(rc_parse_format("TIME") == RC_FORMAT_FRAMES); - assert(rc_parse_format("FRAMES") == RC_FORMAT_FRAMES); - assert(rc_parse_format("SCORE") == RC_FORMAT_SCORE); - assert(rc_parse_format("POINTS") == RC_FORMAT_SCORE); - assert(rc_parse_format("MILLISECS") == RC_FORMAT_CENTISECS); - assert(rc_parse_format("OTHER") == RC_FORMAT_OTHER); - assert(rc_parse_format("INVALID") == RC_FORMAT_VALUE); - } -} - -static rc_lboard_t* parse_lboard(const char* memaddr, void* buffer) { - int ret; - rc_lboard_t* self; - - ret = rc_lboard_size(memaddr); - assert(ret >= 0); - self = rc_parse_lboard(buffer, memaddr, NULL, 0); - assert(self != NULL); - return self; -} - -static void lboard_check(const char* memaddr, int expected_ret) { - int ret = rc_lboard_size(memaddr); - assert(ret == expected_ret); -} - -typedef struct { - int active, submitted; -} -lboard_test_state_t; - -static void lboard_reset(rc_lboard_t* lboard, lboard_test_state_t* state) { - rc_reset_lboard(lboard); - state->active = state->submitted = 0; -} - -static unsigned lboard_evaluate(rc_lboard_t* lboard, lboard_test_state_t* test, memory_t* memory) { - unsigned value; - - switch (rc_evaluate_lboard(lboard, &value, peek, memory, NULL)) { - case RC_LBOARD_STARTED: - test->active = 1; - break; - - case RC_LBOARD_CANCELED: - test->active = 0; - break; - - case RC_LBOARD_TRIGGERED: - test->active = 0; - test->submitted = 1; - break; - } - - return value; -} - -static void test_lboard(void) { - { - /*------------------------------------------------------------------------ - TestSimpleLeaderboard - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - unsigned value; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=1::CAN:0xH00=2::SUB:0xH00=3::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - assert(!state.active); - assert(!state.submitted); - - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 3; /* submit value, but not active */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 2; /* cancel value, but not active */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 1; /* start value */ - value = lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(!state.submitted); - - ram[0] = 2; /* cancel value */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 3; /* submit value, but not active */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 1; /* start value */ - value = lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(!state.submitted); - - ram[0] = 3; /* submit value */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(state.submitted); - assert(value == 0x34U); - } - - { - /*------------------------------------------------------------------------ - TestStartAndCancelSameFrame - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH01=18::SUB:0xH00=3::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[1] = 0x13; /* disables cancel */ - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(!state.submitted); - - ram[1] = 0x12; /* enables cancel */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[1] = 0x13; /* disables cancel, but start condition still true, so it shouldn't restart */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 0x01; /* disables start; no effect this frame, but next frame can restart */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(!state.submitted); - - ram[0] = 0x00; /* enables start */ - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(!state.submitted); - } - - { - /*------------------------------------------------------------------------ - TestStartAndSubmitSameFrame - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - unsigned value; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH01=10::SUB:0xH01=18::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(state.submitted); - assert(value == 0x34U); - - ram[1] = 0; /* disable submit, value should not be resubmitted, */ - value = lboard_evaluate(lboard, &state, &memory); /* start is still true, but leaderboard should not reactivate */ - assert(!state.active); - - ram[0] = 1; /* disable start */ - value = lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - - ram[0] = 0; /* reenable start, leaderboard should reactivate */ - value = lboard_evaluate(lboard, &state, &memory); - assert(state.active); - } - - { - /*------------------------------------------------------------------------ - TestProgress - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - unsigned value; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - value = lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(value == 0x56U); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - value = lboard_evaluate(lboard, &state, &memory); - assert(state.active); - assert(value == 0x34U); - } - - { - /*------------------------------------------------------------------------ - TestStartAndCondition - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0_0xH01=0::CAN:0xH01=10::SUB:0xH01=18::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - - ram[1] = 0; /* second part of start condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - } - - { - /*------------------------------------------------------------------------ - TestStartOrCondition - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:S0xH00=1S0xH01=1::CAN:0xH01=10::SUB:0xH01=18::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - - ram[1] = 1; /* second part of start condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[1] = 0; - lboard_reset(lboard, &state); - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - - ram[0] = 1; /* first part of start condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - } - - { - /*------------------------------------------------------------------------ - TestCancelOrCondition - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:S0xH01=12S0xH02=12::SUB:0xH00=3::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[2] = 12; /* second part of cancel condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - - ram[2] = 0; /* second part of cancel condition is false */ - lboard_reset(lboard, &state); - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[1] = 12; /* first part of cancel condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - } - - { - /*------------------------------------------------------------------------ - TestSubmitAndCondition - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH01=10::SUB:0xH01=18_0xH03=18::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[3] = 18; - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(state.submitted); - } - - { - /*------------------------------------------------------------------------ - TestSubmitOrCondition - ------------------------------------------------------------------------*/ - - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_lboard_t* lboard; - lboard_test_state_t state; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - lboard = parse_lboard("STA:0xH00=0::CAN:0xH01=10::SUB:S0xH01=12S0xH03=12::VAL:0xH02", buffer); - state.active = state.submitted = 0; - - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[3] = 12; /* second part of submit condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(state.submitted); - - ram[3] = 0; - lboard_reset(lboard, &state); - lboard_evaluate(lboard, &state, &memory); - assert(state.active); - - ram[1] = 12; /* first part of submit condition is true */ - lboard_evaluate(lboard, &state, &memory); - assert(!state.active); - assert(state.submitted); - } - - { - /*------------------------------------------------------------------------ - TestUnparsableStringWillNotStart - We'll test for errors in the memaddr field instead - ------------------------------------------------------------------------*/ - - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::GARBAGE", RC_INVALID_LBOARD_FIELD); - lboard_check("CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02", RC_MISSING_START); - lboard_check("STA:0xH00=0::SUB:0xH00=3::PRO:0xH04::VAL:0xH02", RC_MISSING_CANCEL); - lboard_check("STA:0xH00=0::CAN:0xH00=2::PRO:0xH04::VAL:0xH02", RC_MISSING_SUBMIT); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04", RC_MISSING_VALUE); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::STA:0=0", RC_DUPLICATED_START); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::CAN:0=0", RC_DUPLICATED_CANCEL); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::SUB:0=0", RC_DUPLICATED_SUBMIT); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::VAL:0", RC_DUPLICATED_VALUE); - lboard_check("STA:0xH00=0::CAN:0xH00=2::SUB:0xH00=3::PRO:0xH04::VAL:0xH02::PRO:0", RC_DUPLICATED_PROGRESS); - } -} - -static void test_lua(void) { - { - /*------------------------------------------------------------------------ - TestLua - ------------------------------------------------------------------------*/ - -#ifndef RC_DISABLE_LUA - - lua_State* L; - const char* luacheevo = "return { test = function(peek, ud) return peek(0, 4, ud) end }"; - unsigned char ram[] = {0x00, 0x12, 0x34, 0xAB, 0x56}; - memory_t memory; - rc_trigger_t* trigger; - char buffer[2048]; - - memory.ram = ram; - memory.size = sizeof(ram); - - L = luaL_newstate(); - luaL_loadbufferx(L, luacheevo, strlen(luacheevo), "luacheevo.lua", "t"); - lua_call(L, 0, 1); - - memory.ram = ram; - memory.size = sizeof(ram); - - trigger = rc_parse_trigger(buffer, "@test=0xX0", L, 1); - assert(rc_test_trigger(trigger, peek, &memory, L) != 0); - -#endif /* RC_DISABLE_LUA */ - } -} - -int main(void) { - test_operand(); - test_condition(); - test_trigger(); - test_term(); - test_value(); - test_lboard(); - test_lua(); - - return 0; -} diff --git a/discord/discord.c b/discord/discord.c index ba7c3fdc95..4115b86291 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -41,6 +41,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #ifdef HAVE_MENU diff --git a/dynamic.c b/dynamic.c index a8ca1bd2cd..e10b1ea261 100644 --- a/dynamic.c +++ b/dynamic.c @@ -37,6 +37,7 @@ #ifdef HAVE_CHEEVOS #include "cheevos/cheevos.h" +#include "cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #ifdef HAVE_OPENGL @@ -1924,7 +1925,8 @@ bool rarch_environment_cb(unsigned cmd, void *data) { bool state = *(const bool*)data; RARCH_LOG("Environ SET_SUPPORT_ACHIEVEMENTS: %s.\n", state ? "yes" : "no"); - cheevos_set_support_cheevos(state); + /* RCHEEVOS TODO: remove settings test */ + settings->bools.cheevos_rcheevos_enable ? rcheevos_set_support_cheevos(state) : cheevos_set_support_cheevos(state); } #endif break; diff --git a/griffin/griffin.c b/griffin/griffin.c index cecab2d10d..627b86b292 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -158,9 +158,12 @@ ACHIEVEMENTS #include "../libretro-common/formats/json/jsonsax.c" #include "../network/net_http_special.c" -#ifdef HAVE_NEW_CHEEVOS +#include "../cheevos/cheevos.c" +#include "../cheevos/badges.c" +#include "../cheevos/cond.c" +#include "../cheevos/var.c" + #include "../cheevos-new/cheevos.c" -#include "../cheevos-new/badges.c" #include "../cheevos-new/fixup.c" #include "../cheevos-new/hash.c" #include "../cheevos-new/parser.c" @@ -175,13 +178,9 @@ ACHIEVEMENTS #include "../deps/rcheevos/src/rcheevos/term.c" #include "../deps/rcheevos/src/rcheevos/trigger.c" #include "../deps/rcheevos/src/rcheevos/value.c" +#include "../deps/rcheevos/src/rcheevos/memref.c" +#include "../deps/rcheevos/src/rcheevos/richpresence.c" #include "../deps/rcheevos/src/rurl/url.c" -#else -#include "../cheevos/cheevos.c" -#include "../cheevos/badges.c" -#include "../cheevos/cond.c" -#include "../cheevos/var.c" -#endif #endif diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index 1acc87912e..334e558610 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -41,6 +41,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "cheat_manager.h" @@ -68,7 +69,10 @@ unsigned cheat_manager_get_size(void) void cheat_manager_apply_cheats(void) { #ifdef HAVE_CHEEVOS - bool data_bool = false; + /* RCHEEVOS TODO: remove settings init */ + settings_t *settings = config_get_ptr(); + bool data_bool = false; + #endif unsigned i, idx = 0; @@ -100,7 +104,8 @@ void cheat_manager_apply_cheats(void) #ifdef HAVE_CHEEVOS data_bool = idx != 0; - cheevos_apply_cheats(&data_bool); + /* RCHEEVOS TODO: remove settings test */ + settings->bools.cheevos_rcheevos_enable ? rcheevos_apply_cheats(&data_bool) : cheevos_apply_cheats(&data_bool); #endif } diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 5144b7bae4..11885d02c0 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -78,6 +78,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "../../record/record_driver.h" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 35f59907aa..06ebd27a3b 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -21,6 +21,7 @@ #ifdef HAVE_CHEEVOS #include "../../cheevos/cheevos.h" +#include "../../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "../../verbosity.h" @@ -588,12 +589,14 @@ static int action_bind_sublabel_cheevos_entry( char *s, size_t len) { #ifdef HAVE_CHEEVOS + settings_t *settings = config_get_ptr(); /* RCHEEVOS TODO: remove line */ cheevos_ctx_desc_t desc_info; unsigned new_id = type - MENU_SETTINGS_CHEEVOS_START; desc_info.idx = new_id; desc_info.s = s; desc_info.len = len; - cheevos_get_description(&desc_info); + /* RCHEEVOS TODO: remove test */ + settings->bools.cheevos_rcheevos_enable ? rcheevos_get_description((rcheevos_ctx_desc_t*) &desc_info) : cheevos_get_description(&desc_info); strlcpy(s, desc_info.s, len); #endif diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 792e54ee3f..0642e5f048 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -39,6 +39,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #ifdef HAVE_NETWORKING @@ -2667,7 +2668,8 @@ static int menu_displaylist_parse_load_content_settings( if (settings->bools.quick_menu_show_save_load_state #ifdef HAVE_CHEEVOS - && !cheevos_hardcore_active + /* RCHEEVOS TODO: remove 'rcheevos_*' below */ + && !(rcheevos_hardcore_active || cheevos_hardcore_active) #endif ) { @@ -2690,7 +2692,8 @@ static int menu_displaylist_parse_load_content_settings( if (settings->bools.quick_menu_show_save_load_state && settings->bools.quick_menu_show_undo_save_load_state #ifdef HAVE_CHEEVOS - && !cheevos_hardcore_active + /* RCHEEVOS TODO: remove 'rcheevos_*' below */ + && !(rcheevos_hardcore_active || cheevos_hardcore_active) #endif ) { @@ -5564,10 +5567,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist break; case DISPLAYLIST_ACHIEVEMENT_LIST: #ifdef HAVE_CHEEVOS - menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); - cheevos_populate_menu(info); - info->need_push = true; - info->need_refresh = true; + { /* RCHEEVOS TODO: remove brackets, settings and settings test */ + settings_t *settings = config_get_ptr(); + menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); + settings->bools.cheevos_rcheevos_enable ? rcheevos_populate_menu(info) : cheevos_populate_menu(info); + info->need_push = true; + info->need_refresh = true; + } #endif break; diff --git a/menu/menu_setting.c b/menu/menu_setting.c index d9ce82a19b..cee7f710c3 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -50,6 +50,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "../frontend/frontend_driver.h" @@ -3609,7 +3610,8 @@ static void achievement_hardcore_mode_write_handler(rarch_setting_t *setting) if (settings && settings->bools.cheevos_enable && settings->bools.cheevos_hardcore_mode_enable) { - cheevos_toggle_hardcore_mode(); + /* RCHEEVOS TODO: remove settings test */ + settings->bools.cheevos_rcheevos_enable ? rcheevos_toggle_hardcore_mode() : cheevos_toggle_hardcore_mode(); command_event(CMD_EVENT_RESET, NULL); return; } diff --git a/menu/widgets/menu_dialog.c b/menu/widgets/menu_dialog.c index 2fbd65d0b0..5fd0a35c0a 100644 --- a/menu/widgets/menu_dialog.c +++ b/menu/widgets/menu_dialog.c @@ -23,6 +23,7 @@ #ifdef HAVE_CHEEVOS #include "../../cheevos/cheevos.h" +#include "../../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "menu_dialog.h" @@ -173,10 +174,14 @@ int menu_dialog_iterate(char *s, size_t len, const char *label) #ifdef HAVE_CHEEVOS case MENU_DIALOG_HELP_CHEEVOS_DESCRIPTION: - desc_info.idx = menu_dialog_current_id; - desc_info.s = s; - desc_info.len = len; - cheevos_get_description(&desc_info); + { /* RCHEEVOS TODO: remove brackets, settings and settings test */ + settings_t *settings = config_get_ptr(); + desc_info.idx = menu_dialog_current_id; + desc_info.s = s; + desc_info.len = len; + settings->bools.cheevos_rcheevos_enable ? rcheevos_get_description((rcheevos_ctx_desc_t*) &desc_info) : cheevos_get_description(&desc_info); + + } break; #endif diff --git a/network/httpserver/httpserver.c b/network/httpserver/httpserver.c index 607c340511..8831bbf3ae 100644 --- a/network/httpserver/httpserver.c +++ b/network/httpserver/httpserver.c @@ -30,6 +30,7 @@ #include "../../gfx/video_driver.h" #include "../../managers/core_option_manager.h" #include "../../cheevos/cheevos.h" +#include "../../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #include "../../content.h" #define BASIC_INFO "info" diff --git a/qb/config.params.sh b/qb/config.params.sh index 8bb4d964f1..34699330c5 100644 --- a/qb/config.params.sh +++ b/qb/config.params.sh @@ -121,8 +121,6 @@ HAVE_QT=auto # Qt companion support C89_QT=no HAVE_XSHM=no # XShm video driver support HAVE_CHEEVOS=yes # Retro Achievements -HAVE_NEW_CHEEVOS=no # Use rcheevos to process RetroAchievements -C89_NEW_CHEEVOS=no HAVE_LUA=no # Lua support (for Retro Achievements) HAVE_DISCORD=yes # Discord Integration C89_DISCORD=no diff --git a/retroarch.c b/retroarch.c index 1a7bd7a246..cd54d12c61 100644 --- a/retroarch.c +++ b/retroarch.c @@ -79,6 +79,7 @@ #ifdef HAVE_CHEEVOS #include "cheevos/cheevos.h" +#include "cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #ifdef HAVE_DISCORD @@ -3233,7 +3234,8 @@ bool runloop_msg_queue_pull(const char **ret) */ #define time_to_exit(quit_key_pressed) (runloop_shutdown_initiated || quit_key_pressed || !is_alive || bsv_movie_is_end_of_file() || ((runloop_max_frames != 0) && (frame_count >= runloop_max_frames)) || runloop_exec) -#define runloop_check_cheevos() (settings->bools.cheevos_enable && cheevos_loaded && (!cheats_are_enabled && !cheats_were_enabled)) +/* RCHEEVOS TODO: remove 'rcheevos_*' tests below */ +#define runloop_check_cheevos() (settings->bools.cheevos_enable && (rcheevos_loaded || cheevos_loaded) && (!(rcheevos_cheats_are_enabled || cheats_are_enabled) && !(rcheevos_cheats_were_enabled || cheats_were_enabled))) #ifdef HAVE_NETWORKING /* FIXME: This is an ugly way to tell Netplay this... */ @@ -4129,17 +4131,18 @@ static enum runloop_state runloop_check_state( } #ifdef HAVE_CHEEVOS - cheevos_hardcore_active = settings->bools.cheevos_enable + /* RCHEEVOS TODO: remove the 'rcheevos_*' below */ + rcheevos_hardcore_active = cheevos_hardcore_active = settings->bools.cheevos_enable && settings->bools.cheevos_hardcore_mode_enable - && cheevos_loaded && !cheevos_hardcore_paused; + && (rcheevos_loaded || cheevos_loaded) && !(rcheevos_hardcore_paused || cheevos_hardcore_paused); - if (cheevos_hardcore_active && cheevos_state_loaded_flag) + if ((rcheevos_hardcore_active || cheevos_hardcore_active) && (rcheevos_state_loaded_flag || cheevos_state_loaded_flag)) { - cheevos_hardcore_paused = true; + rcheevos_hardcore_paused = cheevos_hardcore_paused = true; runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_DISABLED), 0, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } - if (!cheevos_hardcore_active) + if (!(rcheevos_hardcore_active || cheevos_hardcore_active)) #endif { char s[128]; @@ -4165,7 +4168,8 @@ static enum runloop_state runloop_check_state( /* Checks if slowmotion toggle/hold was being pressed and/or held. */ #ifdef HAVE_CHEEVOS - if (!cheevos_hardcore_active) + /* RCHEEVOS TODO: remove the 'rcheevos_*' below */ + if (!(rcheevos_hardcore_active || cheevos_hardcore_active)) #endif { static bool old_slowmotion_button_state = false; @@ -4521,8 +4525,8 @@ int runloop_iterate(unsigned *sleep_ms) rarch_core_runtime_tick(); #ifdef HAVE_CHEEVOS - if (runloop_check_cheevos()) - cheevos_test(); + if (runloop_check_cheevos()) /* RCHEEVOS TODO: remove settings test */ + settings->bools.cheevos_rcheevos_enable ? rcheevos_test() : cheevos_test(); #endif cheat_manager_apply_retro_cheats(); diff --git a/tasks/task_content.c b/tasks/task_content.c index 8c02546939..4ee24b7cea 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -71,6 +71,7 @@ #ifdef HAVE_CHEEVOS #include "../cheevos/cheevos.h" +#include "../cheevos-new/cheevos.h" /* RCHEEVOS TODO: remove line */ #endif #include "task_content.h" @@ -734,13 +735,15 @@ static bool content_file_load( #ifdef HAVE_CHEEVOS if (!special) { + /* RCHEEVOS TODO: remove settings and settings tests */ + settings_t *settings = config_get_ptr(); const char *content_path = content->elems[0].data; enum rarch_content_type type = path_is_media_type(content_path); - cheevos_set_cheats(); + settings->bools.cheevos_rcheevos_enable ? rcheevos_set_cheats() : cheevos_set_cheats(); if (type == RARCH_CONTENT_NONE && !string_is_empty(content_path)) - cheevos_load(info); + settings->bools.cheevos_rcheevos_enable ? rcheevos_load(info) : cheevos_load(info); } #endif