forked from MiSTer-devel/Main_MiSTer
-
Notifications
You must be signed in to change notification settings - Fork 0
Add live cheat control via MiSTer_cmd #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wizzomafizzo
wants to merge
5
commits into
master
Choose a base branch
from
feat/live-cheat-cmd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07c7a6a
Add live cheat command control
wizzomafizzo a67d0d8
Move cheat command code under Zaparoo support
wizzomafizzo 9bd5b54
Limit cheat command hooks to accessors
wizzomafizzo 48f5c50
Make cheats header self-contained
wizzomafizzo 9fc5f10
Embed Zaparoo Main capability marker
wizzomafizzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <ctype.h> | ||
| #include <stdbool.h> | ||
| #include <inttypes.h> | ||
|
|
||
| #include "cheats.h" | ||
| #include "cheat_cmd.h" | ||
|
|
||
| static const char *skip_space(const char *s) | ||
| { | ||
| while (*s && isspace((unsigned char)*s)) s++; | ||
| return s; | ||
| } | ||
|
|
||
| static bool parse_token(const char **cmd, char *token, size_t token_size) | ||
| { | ||
| const char *s = skip_space(*cmd); | ||
| size_t len = 0; | ||
|
|
||
| while (s[len] && !isspace((unsigned char)s[len])) len++; | ||
| if (!len || len >= token_size) return false; | ||
|
|
||
| memcpy(token, s, len); | ||
| token[len] = 0; | ||
| *cmd = s + len; | ||
| return true; | ||
| } | ||
|
|
||
| static const char *cheat_cmd_status(int status) | ||
| { | ||
| switch (status) | ||
| { | ||
| case CHEATS_CMD_OK: return "ok"; | ||
| case CHEATS_CMD_NO_CHEATS: return "no cheats loaded"; | ||
| case CHEATS_CMD_NOT_FOUND: return "not found"; | ||
| case CHEATS_CMD_LOAD_FAILED: return "load failed"; | ||
| case CHEATS_CMD_NO_ROOM: return "no room"; | ||
| default: return "error"; | ||
| } | ||
| } | ||
|
|
||
| void cheat_cmd(const char *cmd) | ||
| { | ||
| char action[16]; | ||
|
|
||
| if (!parse_token(&cmd, action, sizeof(action))) | ||
| { | ||
| printf("MiSTer_cmd cheat: missing command\n"); | ||
| return; | ||
| } | ||
|
|
||
| if (!strcmp(action, "clear")) | ||
| { | ||
| int status = cheats_clear_enabled(); | ||
| printf("MiSTer_cmd cheat clear: %s\n", cheat_cmd_status(status)); | ||
| return; | ||
| } | ||
|
|
||
| const char *name = skip_space(cmd); | ||
| if (!*name) | ||
| { | ||
| printf("MiSTer_cmd cheat %s: missing name\n", action); | ||
| return; | ||
| } | ||
|
|
||
| int status; | ||
| if (!strcmp(action, "on")) status = cheats_set_enabled_by_name(name, true); | ||
| else if (!strcmp(action, "off")) status = cheats_set_enabled_by_name(name, false); | ||
| else if (!strcmp(action, "toggle")) status = cheats_toggle_by_name(name); | ||
| else | ||
| { | ||
| printf("MiSTer_cmd cheat: unknown command '%s'\n", action); | ||
| return; | ||
| } | ||
|
|
||
| printf("MiSTer_cmd cheat %s '%s': %s\n", action, name, cheat_cmd_status(status)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #ifndef CHEAT_CMD_H | ||
| #define CHEAT_CMD_H | ||
|
|
||
| void cheat_cmd(const char *cmd); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift
Move this new backend command-control block into a new file and keep this upstream file to a hook-level change.
Lines 463-579 introduce substantial new functionality directly in
cheats.cpp. Please extract this logic into a new.cpp/.hpair and keep upstreamcheats.cppedits minimal (bridge/hook only).As per coding guidelines, “Put new functionality in new
.cpp/.hfiles wherever possible rather than modifying upstream source files…” and “When touching upstream source files, make only surgical edits: add a single#include, a single function call, or a single hook point.”🤖 Prompt for AI Agents