mirror of
https://github.com/holub/mame
synced 2025-07-03 09:06:08 +03:00
Added built-in "Off" states to the cheats with parameters. This is
also the default state, obviating the need for a default value. Removed the "default" attribute as a result. Switching from "Off" to another state first executes the "on" script followed by the "change" script. Switching to "Off" from another state executes the "off" script. While not off, the "run" script is executed each frame.
This commit is contained in:
parent
8c9f7cbc76
commit
89730e4d28
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<mamecheat version="1">
|
<mamecheat version="1">
|
||||||
<cheat desc="blah">
|
<cheat desc="blah">
|
||||||
<parameter min="minval(0)" max="maxval(numitems)" step="stepval(1)" default="defvalue(minval)">
|
<parameter min="minval(0)" max="maxval(numitems)" step="stepval(1)">
|
||||||
<item value="itemval(previtemval|minval+stepval)">text</item>
|
<item value="itemval(previtemval|minval+stepval)">text</item>
|
||||||
...
|
...
|
||||||
</parameter>
|
</parameter>
|
||||||
@ -110,8 +110,6 @@ struct _cheat_parameter
|
|||||||
int maxformat; /* format of maximum value */
|
int maxformat; /* format of maximum value */
|
||||||
UINT64 stepval; /* step value */
|
UINT64 stepval; /* step value */
|
||||||
int stepformat; /* format of step value */
|
int stepformat; /* format of step value */
|
||||||
UINT64 defval; /* default value */
|
|
||||||
int defformat; /* format of default value */
|
|
||||||
UINT64 value; /* live value of the parameter */
|
UINT64 value; /* live value of the parameter */
|
||||||
char valuestring[32]; /* small space for a value string */
|
char valuestring[32]; /* small space for a value string */
|
||||||
parameter_item * itemlist; /* list of items */
|
parameter_item * itemlist; /* list of items */
|
||||||
@ -393,6 +391,15 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
|
|
||||||
/* if we have a value parameter, compute it */
|
/* if we have a value parameter, compute it */
|
||||||
else if (cheat->parameter->itemlist == NULL)
|
else if (cheat->parameter->itemlist == NULL)
|
||||||
|
{
|
||||||
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
if (state != NULL)
|
||||||
|
*state = "Off";
|
||||||
|
if (flags != NULL)
|
||||||
|
*flags = MENU_FLAG_RIGHT_ARROW;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (state != NULL)
|
if (state != NULL)
|
||||||
{
|
{
|
||||||
@ -401,18 +408,26 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
}
|
}
|
||||||
if (flags != NULL)
|
if (flags != NULL)
|
||||||
{
|
{
|
||||||
*flags = 0;
|
*flags = MENU_FLAG_LEFT_ARROW;
|
||||||
if (cheat->parameter->value > cheat->parameter->minval)
|
|
||||||
*flags |= MENU_FLAG_LEFT_ARROW;
|
|
||||||
if (cheat->parameter->value < cheat->parameter->maxval)
|
if (cheat->parameter->value < cheat->parameter->maxval)
|
||||||
*flags |= MENU_FLAG_RIGHT_ARROW;
|
*flags |= MENU_FLAG_RIGHT_ARROW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* if we have an item list, pick the index */
|
/* if we have an item list, pick the index */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
parameter_item *item, *prev = NULL;
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
if (state != NULL)
|
||||||
|
*state = "Off";
|
||||||
|
if (flags != NULL)
|
||||||
|
*flags = MENU_FLAG_RIGHT_ARROW;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parameter_item *item = NULL, *prev = NULL;
|
||||||
|
|
||||||
for (item = cheat->parameter->itemlist; item != NULL; prev = item, item = item->next)
|
for (item = cheat->parameter->itemlist; item != NULL; prev = item, item = item->next)
|
||||||
if (item->value == cheat->parameter->value)
|
if (item->value == cheat->parameter->value)
|
||||||
@ -421,13 +436,12 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
*state = (item != NULL) ? astring_c(item->text) : "??Invalid??";
|
*state = (item != NULL) ? astring_c(item->text) : "??Invalid??";
|
||||||
if (flags != NULL)
|
if (flags != NULL)
|
||||||
{
|
{
|
||||||
*flags = 0;
|
*flags = MENU_FLAG_LEFT_ARROW;
|
||||||
if (item == NULL || prev != NULL)
|
|
||||||
*flags |= MENU_FLAG_LEFT_ARROW;
|
|
||||||
if (item == NULL || item->next != NULL)
|
if (item == NULL || item->next != NULL)
|
||||||
*flags |= MENU_FLAG_RIGHT_ARROW;
|
*flags |= MENU_FLAG_RIGHT_ARROW;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* return a pointer to this item */
|
/* return a pointer to this item */
|
||||||
return cheat;
|
return cheat;
|
||||||
@ -473,7 +487,7 @@ int cheat_select_default_state(running_machine *machine, void *entry)
|
|||||||
;
|
;
|
||||||
|
|
||||||
/* if we have no parameter, it's just on/off; default to off */
|
/* if we have no parameter, it's just on/off; default to off */
|
||||||
else if (cheat->parameter == NULL)
|
else
|
||||||
{
|
{
|
||||||
if (cheat->state != SCRIPT_STATE_OFF)
|
if (cheat->state != SCRIPT_STATE_OFF)
|
||||||
{
|
{
|
||||||
@ -482,16 +496,6 @@ int cheat_select_default_state(running_machine *machine, void *entry)
|
|||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we have a value parameter, fall back to the default */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (cheat->parameter->value != cheat->parameter->defval)
|
|
||||||
{
|
|
||||||
cheat->parameter->value = cheat->parameter->defval;
|
|
||||||
changed = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,6 +538,12 @@ int cheat_select_previous_state(running_machine *machine, void *entry)
|
|||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (cheat->state != SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_OFF);
|
||||||
|
cheat->state = SCRIPT_STATE_OFF;
|
||||||
|
changed = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we have an item list, pick the index */
|
/* if we have an item list, pick the index */
|
||||||
@ -546,10 +556,21 @@ int cheat_select_previous_state(running_machine *machine, void *entry)
|
|||||||
break;
|
break;
|
||||||
if (prev != NULL)
|
if (prev != NULL)
|
||||||
{
|
{
|
||||||
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
|
}
|
||||||
cheat->parameter->value = prev->value;
|
cheat->parameter->value = prev->value;
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
|
else if (cheat->state != SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_OFF);
|
||||||
|
cheat->state = SCRIPT_STATE_OFF;
|
||||||
|
changed = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
@ -584,7 +605,15 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
/* if we have a value parameter, compute it */
|
/* if we have a value parameter, compute it */
|
||||||
else if (cheat->parameter->itemlist == NULL)
|
else if (cheat->parameter->itemlist == NULL)
|
||||||
{
|
{
|
||||||
if (cheat->parameter->value < cheat->parameter->maxval)
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
|
cheat->parameter->value = cheat->parameter->minval;
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
|
changed = TRUE;
|
||||||
|
}
|
||||||
|
else if (cheat->parameter->value < cheat->parameter->maxval)
|
||||||
{
|
{
|
||||||
if (cheat->parameter->value > cheat->parameter->maxval - cheat->parameter->stepval)
|
if (cheat->parameter->value > cheat->parameter->maxval - cheat->parameter->stepval)
|
||||||
cheat->parameter->value = cheat->parameter->maxval;
|
cheat->parameter->value = cheat->parameter->maxval;
|
||||||
@ -600,6 +629,16 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
{
|
{
|
||||||
parameter_item *item;
|
parameter_item *item;
|
||||||
|
|
||||||
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
|
cheat->parameter->value = cheat->parameter->itemlist->value;
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
|
changed = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (item = cheat->parameter->itemlist; item != NULL; item = item->next)
|
for (item = cheat->parameter->itemlist; item != NULL; item = item->next)
|
||||||
if (item->value == cheat->parameter->value)
|
if (item->value == cheat->parameter->value)
|
||||||
break;
|
break;
|
||||||
@ -610,6 +649,7 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,7 +1013,7 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* set the initial state */
|
/* set the initial state */
|
||||||
cheat->state = (cheat->parameter != NULL) ? SCRIPT_STATE_RUN : SCRIPT_STATE_OFF;
|
cheat->state = SCRIPT_STATE_OFF;
|
||||||
return cheat;
|
return cheat;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -1078,8 +1118,6 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
|
|||||||
param->maxformat = xml_get_attribute_int_format(paramnode, "max");
|
param->maxformat = xml_get_attribute_int_format(paramnode, "max");
|
||||||
param->stepval = xml_get_attribute_int(paramnode, "step", 1);
|
param->stepval = xml_get_attribute_int(paramnode, "step", 1);
|
||||||
param->stepformat = xml_get_attribute_int_format(paramnode, "step");
|
param->stepformat = xml_get_attribute_int_format(paramnode, "step");
|
||||||
param->defval = xml_get_attribute_int(paramnode, "default", param->minval);
|
|
||||||
param->defformat = xml_get_attribute_int_format(paramnode, "default");
|
|
||||||
|
|
||||||
/* iterate over items */
|
/* iterate over items */
|
||||||
itemtailptr = ¶m->itemlist;
|
itemtailptr = ¶m->itemlist;
|
||||||
@ -1116,10 +1154,8 @@ static cheat_parameter *cheat_parameter_load(const char *filename, xml_data_node
|
|||||||
itemtailptr = &curitem->next;
|
itemtailptr = &curitem->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if no default, pick the minimum */
|
/* start at the minimum */
|
||||||
if (xml_get_attribute_string(paramnode, "default", NULL) == NULL)
|
param->value = param->minval;
|
||||||
param->defval = (param->itemlist != NULL) ? param->itemlist->value : param->minval;
|
|
||||||
param->value = param->defval;
|
|
||||||
|
|
||||||
return param;
|
return param;
|
||||||
|
|
||||||
@ -1150,7 +1186,6 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
|
|||||||
mame_fprintf(cheatfile, " max=\"%s\"", format_int(string, param->maxval, param->maxformat));
|
mame_fprintf(cheatfile, " max=\"%s\"", format_int(string, param->maxval, param->maxformat));
|
||||||
if (param->stepval != 1)
|
if (param->stepval != 1)
|
||||||
mame_fprintf(cheatfile, " step=\"%s\"", format_int(string, param->stepval, param->stepformat));
|
mame_fprintf(cheatfile, " step=\"%s\"", format_int(string, param->stepval, param->stepformat));
|
||||||
mame_fprintf(cheatfile, " default=\"%s\"", format_int(string, param->defval, param->defformat));
|
|
||||||
mame_fprintf(cheatfile, "/>\n");
|
mame_fprintf(cheatfile, "/>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,7 +1194,6 @@ static void cheat_parameter_save(mame_file *cheatfile, const cheat_parameter *pa
|
|||||||
{
|
{
|
||||||
const parameter_item *curitem;
|
const parameter_item *curitem;
|
||||||
|
|
||||||
mame_fprintf(cheatfile, " default=\"%s\">\n", format_int(string, param->defval, param->defformat));
|
|
||||||
for (curitem = param->itemlist; curitem != NULL; curitem = curitem->next)
|
for (curitem = param->itemlist; curitem != NULL; curitem = curitem->next)
|
||||||
mame_fprintf(cheatfile, "\t\t\t<item value=\"%s\">%s</item>\n", format_int(string, curitem->value, curitem->valformat), astring_c(curitem->text));
|
mame_fprintf(cheatfile, "\t\t\t<item value=\"%s\">%s</item>\n", format_int(string, curitem->value, curitem->valformat), astring_c(curitem->text));
|
||||||
mame_fprintf(cheatfile, "\t\t</parameter>\n");
|
mame_fprintf(cheatfile, "\t\t</parameter>\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user