summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cheat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/cheat.c')
-rw-r--r--src/emu/cheat.c222
1 files changed, 111 insertions, 111 deletions
diff --git a/src/emu/cheat.c b/src/emu/cheat.c
index 98c7072c62d..26525b085fd 100644
--- a/src/emu/cheat.c
+++ b/src/emu/cheat.c
@@ -9,26 +9,26 @@
**********************************************************************
- Cheat XML format:
-
- <mamecheat version="1">
- <cheat desc="blah">
- <parameter variable="varname(param)" min="minval(0)" max="maxval(numitems)" step="stepval(1)">
- <item value="itemval(previtemval|minval+stepval)">text</item>
- ...
- </parameter>
- <script state="on|off|run|change(run)">
- <action condition="condexpr(1)">expression</action>
- ...
- <output condition="condexpr(1)" format="format(required)" line="line(0)" align="left|center|right(left)">
- <argument count="count(1)">expression</argument>
- </output>
- ...
- </script>
- ...
- </cheat>
- ...
- </mamecheat>
+ Cheat XML format:
+
+ <mamecheat version="1">
+ <cheat desc="blah">
+ <parameter variable="varname(param)" min="minval(0)" max="maxval(numitems)" step="stepval(1)">
+ <item value="itemval(previtemval|minval+stepval)">text</item>
+ ...
+ </parameter>
+ <script state="on|off|run|change(run)">
+ <action condition="condexpr(1)">expression</action>
+ ...
+ <output condition="condexpr(1)" format="format(required)" line="line(0)" align="left|center|right(left)">
+ <argument count="count(1)">expression</argument>
+ </output>
+ ...
+ </script>
+ ...
+ </cheat>
+ ...
+ </mamecheat>
*********************************************************************/
@@ -190,16 +190,16 @@ static void cheat_variable_set(void *ref, UINT64 value);
/*-------------------------------------------------
cheat_init - initialize the cheat engine,
- loading the cheat file
+ loading the cheat file
-------------------------------------------------*/
void cheat_init(running_machine *machine)
{
cheat_private *cheatinfo;
-
+
/* request a callback */
add_exit_callback(machine, cheat_exit);
-
+
/* allocate memory */
cheatinfo = auto_malloc(sizeof(*cheatinfo));
memset(cheatinfo, 0, sizeof(*cheatinfo));
@@ -221,7 +221,7 @@ void cheat_init(running_machine *machine)
static void cheat_exit(running_machine *machine)
{
cheat_private *cheatinfo = machine->cheat_data;
-
+
/* free the list of cheats */
if (cheatinfo->cheatlist != NULL)
cheat_list_free(cheatinfo->cheatlist);
@@ -235,7 +235,7 @@ static void cheat_exit(running_machine *machine)
/*-------------------------------------------------
cheat_list_load - load a cheat file into
- memory and create the cheat entry list
+ memory and create the cheat entry list
-------------------------------------------------*/
static cheat_entry *cheat_list_load(const char *filename)
@@ -258,7 +258,7 @@ static cheat_entry *cheat_list_load(const char *filename)
/* if that failed, return nothing */
if (filerr != FILERR_NONE)
return NULL;
-
+
/* read the XML file into internal data structures */
memset(&options, 0, sizeof(options));
options.error = &error;
@@ -316,7 +316,7 @@ error:
/*-------------------------------------------------
cheat_list_save - save a cheat file from
- memory to the given filename
+ memory to the given filename
-------------------------------------------------*/
static int cheat_list_save(const char *filename, const cheat_entry *cheatlist)
@@ -333,16 +333,16 @@ static int cheat_list_save(const char *filename, const cheat_entry *cheatlist)
/* if that failed, return nothing */
if (filerr != FILERR_NONE)
return FALSE;
-
+
/* output the outer layers */
mame_fprintf(cheatfile, "<?xml version=\"1.0\"?>\n");
mame_fprintf(cheatfile, "<!-- This file is autogenerated; comments and unknown tags will be stripped -->\n");
mame_fprintf(cheatfile, "<mamecheat version=\"%d\">\n", CHEAT_VERSION);
-
+
/* iterate over cheats in the list and save them */
for ( ; cheatlist != NULL; cheatlist = cheatlist->next)
cheat_entry_save(cheatfile, cheatlist);
-
+
/* close out the file */
mame_fprintf(cheatfile, "</mamecheat>\n");
mame_fclose(cheatfile);
@@ -367,8 +367,8 @@ static void cheat_list_free(cheat_entry *cheat)
/*-------------------------------------------------
cheat_entry_load - load a single cheat
- entry and create the underlying data
- structures
+ entry and create the underlying data
+ structures
-------------------------------------------------*/
static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatnode)
@@ -377,7 +377,7 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
const char *description;
int tempcount, curtemp;
cheat_entry *cheat;
-
+
/* pull the variable count out ahead of things */
tempcount = xml_get_attribute_int(cheatnode, "tempvariables", DEFAULT_TEMP_VARIABLES);
if (tempcount < 1)
@@ -385,12 +385,12 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
mame_printf_error("%s.xml(%d): invalid tempvariables attribute (%d)\n", filename, cheatnode->line, tempcount);
return NULL;
}
-
+
/* allocate memory for the cheat */
cheat = malloc_or_die(sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar));
memset(cheat, 0, sizeof(*cheat) + (tempcount - 1) * sizeof(cheat->tempvar));
cheat->numtemp = tempcount;
-
+
/* get the description */
description = xml_get_attribute_string(cheatnode, "desc", NULL);
if (description == NULL || description[0] == 0)
@@ -399,7 +399,7 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
return NULL;
}
cheat->description = astring_dupc(description);
-
+
/* create the symbol table */
cheat->symbols = symtable_alloc(NULL);
for (curtemp = 0; curtemp < tempcount; curtemp++)
@@ -408,7 +408,7 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
sprintf(tempname, "temp%d", curtemp);
symtable_add_register(cheat->symbols, tempname, &cheat->tempvar[curtemp], cheat_variable_get, cheat_variable_set);
}
-
+
/* read the first parameter node */
paramnode = xml_get_sibling(cheatnode->child, "parameter");
if (paramnode != NULL)
@@ -421,7 +421,7 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
/* set this as the parameter and add the symbol */
cheat->parameter = curparam;
symtable_add_register(cheat->symbols, astring_c(curparam->name), &curparam->value, cheat_variable_get, cheat_variable_set);
-
+
/* only one parameter allowed */
paramnode = xml_get_sibling(paramnode->next, "parameter");
if (paramnode != NULL)
@@ -435,11 +435,11 @@ static cheat_entry *cheat_entry_load(const char *filename, xml_data_node *cheatn
cheat_script *curscript = cheat_script_load(filename, scriptnode, cheat);
if (curscript == NULL)
goto error;
-
+
/* if we have a script already for this slot, it is an error */
if (cheat->script[curscript->state] != NULL)
mame_printf_warning("%s.xml(%d): only one script per state allowed; ignoring additional scripts\n", filename, scriptnode->line);
-
+
/* otherwise, fill in the slot */
else
cheat->script[curscript->state] = curscript;
@@ -454,28 +454,28 @@ error:
/*-------------------------------------------------
cheat_entry_save - save a single cheat
- entry
+ entry
-------------------------------------------------*/
static void cheat_entry_save(mame_file *cheatfile, const cheat_entry *cheat)
{
script_state state;
-
+
/* output the cheat tag */
mame_fprintf(cheatfile, "\t<cheat desc=\"%s\"", astring_c(cheat->description));
if (cheat->numtemp != DEFAULT_TEMP_VARIABLES)
mame_fprintf(cheatfile, " tempvariables=\"%d\"", cheat->numtemp);
mame_fprintf(cheatfile, ">\n");
-
+
/* output the parameter, if present */
if (cheat->parameter != NULL)
cheat_parameter_save(cheatfile, cheat->parameter);
-
+
/* output the script nodes */
for (state = SCRIPT_STATE_OFF; state < SCRIPT_STATE_COUNT; state++)
if (cheat->script[state] != NULL)
cheat_script_save(cheatfile, cheat->script[state]);
-
+
/* close the cheat tag */
mame_fprintf(cheatfile, "\t</cheat>\n");
}
@@ -491,25 +491,25 @@ static void cheat_entry_free(cheat_entry *cheat)
if (cheat->description != NULL)
astring_free(cheat->description);
-
+
if (cheat->parameter != NULL)
cheat_parameter_free(cheat->parameter);
-
+
for (state = SCRIPT_STATE_OFF; state < SCRIPT_STATE_COUNT; state++)
if (cheat->script[state] != NULL)
cheat_script_free(cheat->script[state]);
-
+
if (cheat->symbols != NULL)
symtable_free(cheat->symbols);
-
+
free(cheat);
}
/*-------------------------------------------------
cheat_parameter_load - load a single cheat
- parameter and create the underlying data
- structures
+ parameter and create the underlying data
+ structures
-------------------------------------------------*/
static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node *paramnode)
@@ -517,27 +517,27 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
parameter_item **itemtailptr;
xml_data_node *itemnode;
cheat_parameter *param;
-
+
/* allocate memory for it */
param = malloc_or_die(sizeof(*param));
memset(param, 0, sizeof(*param));
-
+
/* read the core attributes */
param->name = astring_dupc(xml_get_attribute_string(paramnode, "variable", "param"));
param->minval = xml_get_attribute_int(paramnode, "min", 0);
param->maxval = xml_get_attribute_int(paramnode, "max", 0);
param->stepval = xml_get_attribute_int(paramnode, "step", 1);
-
+
/* iterate over items */
itemtailptr = &param->itemlist;
for (itemnode = xml_get_sibling(paramnode->child, "item"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "item"))
{
parameter_item *curitem;
-
+
/* allocate memory for it */
curitem = malloc_or_die(sizeof(*curitem));
memset(curitem, 0, sizeof(*curitem));
-
+
/* check for NULL text */
if (itemnode->value == NULL || itemnode->value[0] == 0)
{
@@ -545,7 +545,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
goto error;
}
curitem->text = astring_dupc(itemnode->value);
-
+
/* read the attributes */
if (xml_get_attribute(itemnode, "value") == NULL)
{
@@ -553,7 +553,7 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
goto error;
}
curitem->value = xml_get_attribute_int(itemnode, "value", 0);
-
+
/* add to the end of the list */
*itemtailptr = curitem;
itemtailptr = &curitem->next;
@@ -568,7 +568,7 @@ error:
/*-------------------------------------------------
cheat_parameter_save - save a single cheat
- parameter
+ parameter
-------------------------------------------------*/
static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *param)
@@ -592,7 +592,7 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
else
{
const parameter_item *curitem;
-
+
mame_fprintf(cheatfile, ">\n");
for (curitem = param->itemlist; curitem != NULL; curitem = curitem->next)
mame_fprintf(cheatfile, "\t\t\t<item value=\"%d\">%s</item>\n", (UINT32)curitem->value, astring_c(curitem->text));
@@ -602,33 +602,33 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
/*-------------------------------------------------
- cheat_parameter_free - free a single cheat
- parameter
+ cheat_parameter_free - free a single cheat
+ parameter
-------------------------------------------------*/
static void cheat_parameter_free(cheat_parameter *param)
{
if (param->name != NULL)
astring_free(param->name);
-
+
while (param->itemlist != NULL)
{
parameter_item *item = param->itemlist;
param->itemlist = item->next;
-
+
if (item->text != NULL)
astring_free(item->text);
free(item);
}
-
+
free(param);
}
-
+
/*-------------------------------------------------
cheat_script_load - load a single cheat
- script and create the underlying data
- structures
+ script and create the underlying data
+ structures
-------------------------------------------------*/
static cheat_script *cheat_script_load(const char *filename, xml_data_node *scriptnode, cheat_entry *cheat)
@@ -637,11 +637,11 @@ static cheat_script *cheat_script_load(const char *filename, xml_data_node *scri
xml_data_node *entrynode;
cheat_script *script;
const char *state;
-
+
/* allocate memory for it */
script = malloc_or_die(sizeof(*script));
memset(script, 0, sizeof(*script));
-
+
/* read the core attributes */
script->state = SCRIPT_STATE_RUN;
state = xml_get_attribute_string(scriptnode, "state", "run");
@@ -656,21 +656,21 @@ static cheat_script *cheat_script_load(const char *filename, xml_data_node *scri
mame_printf_error("%s.xml(%d): invalid script state '%s'\n", filename, scriptnode->line, state);
goto error;
}
-
+
/* iterate over nodes within the script */
entrytailptr = &script->entrylist;
for (entrynode = scriptnode->child; entrynode != NULL; entrynode = entrynode->next)
{
script_entry *curentry = NULL;
-
+
/* handle action nodes */
if (strcmp(entrynode->name, "action") == 0)
curentry = script_entry_load(filename, entrynode, cheat, TRUE);
-
+
/* handle output nodes */
else if (strcmp(entrynode->name, "output") == 0)
curentry = script_entry_load(filename, entrynode, cheat, FALSE);
-
+
/* anything else is ignored */
else
{
@@ -686,7 +686,7 @@ static cheat_script *cheat_script_load(const char *filename, xml_data_node *scri
entrytailptr = &curentry->next;
}
return script;
-
+
error:
cheat_script_free(script);
return NULL;
@@ -695,7 +695,7 @@ error:
/*-------------------------------------------------
cheat_script_save - save a single cheat
- script
+ script
-------------------------------------------------*/
static void cheat_script_save(mame_file *cheatfile, const cheat_script *script)
@@ -713,19 +713,19 @@ static void cheat_script_save(mame_file *cheatfile, const cheat_script *script)
case SCRIPT_STATE_CHANGE: mame_fprintf(cheatfile, " state=\"change\""); break;
}
mame_fprintf(cheatfile, ">\n");
-
+
/* output entries */
for (entry = script->entrylist; entry != NULL; entry = entry->next)
script_entry_save(cheatfile, entry);
-
+
/* close the tag */
mame_fprintf(cheatfile, "\t\t</script>\n");
}
/*-------------------------------------------------
- cheat_script_free - free a single cheat
- script
+ cheat_script_free - free a single cheat
+ script
-------------------------------------------------*/
static void cheat_script_free(cheat_script *script)
@@ -736,15 +736,15 @@ static void cheat_script_free(cheat_script *script)
script->entrylist = entry->next;
script_entry_free(entry);
}
-
+
free(script);
}
/*-------------------------------------------------
script_entry_load - load a single action
- or output create the underlying data
- structures
+ or output create the underlying data
+ structures
-------------------------------------------------*/
static script_entry *script_entry_load(const char *filename, xml_data_node *entrynode, cheat_entry *cheat, int isaction)
@@ -752,11 +752,11 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
const char *expression;
script_entry *entry;
EXPRERR experr;
-
+
/* allocate memory for it */
entry = malloc_or_die(sizeof(*entry));
memset(entry, 0, sizeof(*entry));
-
+
/* read the condition if present */
expression = xml_get_attribute_string(entrynode, "condition", NULL);
if (expression != NULL)
@@ -768,7 +768,7 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
goto error;
}
}
-
+
/* if this is an action, parse the expression */
if (isaction)
{
@@ -785,14 +785,14 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
goto error;
}
}
-
+
/* otherwise, parse the attributes and arguments */
else
{
output_argument **argtailptr;
const char *align, *format;
xml_data_node *argnode;
-
+
/* extract format */
format = xml_get_attribute_string(entrynode, "format", NULL);
if (format == NULL || format[0] == 0)
@@ -815,7 +815,7 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
mame_printf_error("%s.xml(%d): invalid alignment '%s' specified\n", filename, entrynode->line, align);
goto error;
}
-
+
/* then parse arguments */
argtailptr = &entry->arglist;
for (argnode = xml_get_sibling(entrynode->child, "argument"); argnode != NULL; argnode = xml_get_sibling(argnode->next, "argument"))
@@ -825,10 +825,10 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
/* allocate memory for it */
curarg = malloc_or_die(sizeof(*curarg));
memset(curarg, 0, sizeof(*curarg));
-
+
/* first extract attributes */
curarg->count = xml_get_attribute_int(argnode, "count", 1);
-
+
/* read the expression */
expression = argnode->value;
if (expression == NULL || expression[0] == 0)
@@ -847,7 +847,7 @@ static script_entry *script_entry_load(const char *filename, xml_data_node *entr
*argtailptr = curarg;
argtailptr = &curarg->next;
}
-
+
/* validate the format against the arguments */
if (!validate_format(filename, entrynode->line, entry))
goto error;
@@ -862,13 +862,13 @@ error:
/*-------------------------------------------------
script_entry_save - save a single action
- or output
+ or output
-------------------------------------------------*/
static void script_entry_save(mame_file *cheatfile, const script_entry *entry)
{
astring *tempstring = astring_alloc();
-
+
/* output an action */
if (entry->format == NULL)
{
@@ -881,7 +881,7 @@ static void script_entry_save(mame_file *cheatfile, const script_entry *entry)
quote_astring(astring_cpyc(tempstring, expression_original_string(entry->expression)), FALSE);
mame_fprintf(cheatfile, ">%s</action>\n", astring_c(tempstring));
}
-
+
/* output an output */
else
{
@@ -899,12 +899,12 @@ static void script_entry_save(mame_file *cheatfile, const script_entry *entry)
mame_fprintf(cheatfile, " align=\"right\"");
if (entry->arglist == NULL)
mame_fprintf(cheatfile, " />\n");
-
+
/* output arguments */
else
{
const output_argument *curarg;
-
+
mame_fprintf(cheatfile, ">\n");
for (curarg = entry->arglist; curarg != NULL; curarg = curarg->next)
{
@@ -917,14 +917,14 @@ static void script_entry_save(mame_file *cheatfile, const script_entry *entry)
mame_fprintf(cheatfile, "\t\t\t</output>\n");
}
}
-
+
astring_free(tempstring);
}
/*-------------------------------------------------
- script_entry_free - free a single script
- entry
+ script_entry_free - free a single script
+ entry
-------------------------------------------------*/
static void script_entry_free(script_entry *entry)
@@ -935,17 +935,17 @@ static void script_entry_free(script_entry *entry)
expression_free(entry->expression);
if (entry->format != NULL)
astring_free(entry->format);
-
+
while (entry->arglist != NULL)
{
output_argument *curarg = entry->arglist;
entry->arglist = curarg->next;
-
+
if (curarg->expression != NULL)
expression_free(curarg->expression);
free(curarg);
}
-
+
free(entry);
}
@@ -957,7 +957,7 @@ static void script_entry_free(script_entry *entry)
/*-------------------------------------------------
quote_astring - quote a string so that it
- is valid to embed in an XML document
+ is valid to embed in an XML document
-------------------------------------------------*/
static astring *quote_astring(astring *string, int isattribute)
@@ -972,7 +972,7 @@ static astring *quote_astring(astring *string, int isattribute)
/*-------------------------------------------------
validate_format - check that a format string
- has the correct number and type of arguments
+ has the correct number and type of arguments
-------------------------------------------------*/
static int validate_format(const char *filename, int line, const script_entry *entry)
@@ -981,12 +981,12 @@ static int validate_format(const char *filename, int line, const script_entry *e
const output_argument *curarg;
int argsprovided;
int argscounted;
-
+
/* first count arguments */
argsprovided = 0;
for (curarg = entry->arglist; curarg != NULL; curarg = curarg->next)
argsprovided += curarg->count;
-
+
/* now scan the string for valid argument usage */
p = strchr(p, '%');
argscounted = 0;
@@ -996,7 +996,7 @@ static int validate_format(const char *filename, int line, const script_entry *e
p++;
while (strchr("lh0123456789.-+ #", *p) != NULL)
p++;
-
+
/* look for a valid type */
if (strchr("cdiouxX", *p) == NULL)
{
@@ -1008,7 +1008,7 @@ static int validate_format(const char *filename, int line, const script_entry *e
/* look for the next one */
p = strchr(p, '%');
}
-
+
/* did we match? */
if (argscounted < argsprovided)
{
@@ -1026,7 +1026,7 @@ static int validate_format(const char *filename, int line, const script_entry *e
/*-------------------------------------------------
cheat_variable_get - return the value of a
- cheat variable
+ cheat variable
-------------------------------------------------*/
static UINT64 cheat_variable_get(void *ref)
@@ -1037,7 +1037,7 @@ static UINT64 cheat_variable_get(void *ref)
/*-------------------------------------------------
cheat_variable_set - set the value of a
- cheat variable
+ cheat variable
-------------------------------------------------*/
static void cheat_variable_set(void *ref, UINT64 value)