mirror of
https://github.com/holub/mame
synced 2025-05-21 13:18:56 +03:00
In addition to this change I added inline functions to define the
various cheat types and a table at the top to hopefully alleviate confusion. From: Pugsy [mailto:pugsy@gmx.net] Sent: Sunday, March 15, 2009 11:01 AM To: submit@mamedev.org Subject: Cheat.c changes I've been having a look at cheat.c, the issue with one-shot list and one-shot select value cheats being indisguishable from perm cheats. I decided to have a look to see if I get it closer to the old way. I think I've managed it. I've attached a diff file.. It changes the One-Shot List or Selectable value cheats to display "Set" instead of "Off" It stops the cheat options being activated in order when you are going through the possibilities These cheats are now activated by pressing ENTER after you have chosen an option This also pops up a message (examples): Activated Select Starting Stage = 16 (0x10) or Activated Select Temp. Current Shape PL1 = Yellow Some simple examples to look at: theroes "Select Starting Stage" and tetrist "Select Temp. Current Shape PL1" Martin 'Pugsy' Pugh
This commit is contained in:
parent
52a8ab6014
commit
c8585dd236
156
src/emu/cheat.c
156
src/emu/cheat.c
@ -51,6 +51,26 @@
|
|||||||
variables may be requested via the 'tempvariables' attribute
|
variables may be requested via the 'tempvariables' attribute
|
||||||
on the cheat.
|
on the cheat.
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
Cheats are generally broken down into categories based on
|
||||||
|
which actions are defined and whether or not there is a
|
||||||
|
parameter present:
|
||||||
|
|
||||||
|
---- Actions -----
|
||||||
|
On Off Run Chg Param? Type
|
||||||
|
=== === === === ====== =================================
|
||||||
|
N N N ? None Text-only (displays text in menu)
|
||||||
|
Y N N ? None Oneshot (select to activate)
|
||||||
|
Y Y N ? None On/Off (select to toggle)
|
||||||
|
? ? Y ? None On/Off (select to toggle)
|
||||||
|
|
||||||
|
? N N Y Any Oneshot parameter (select to alter)
|
||||||
|
? Y ? ? Value Value parameter (off or a live value)
|
||||||
|
? ? Y ? Value Value parameter (off or a live value)
|
||||||
|
? Y ? ? List Item list parameter (off or a live value)
|
||||||
|
? ? Y ? List Item list parameter (off or a live value)
|
||||||
|
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
#include "driver.h"
|
#include "driver.h"
|
||||||
@ -98,6 +118,7 @@ struct _parameter_item
|
|||||||
astring * text; /* name of the item */
|
astring * text; /* name of the item */
|
||||||
UINT64 value; /* value of the item */
|
UINT64 value; /* value of the item */
|
||||||
int valformat; /* format of value */
|
int valformat; /* format of value */
|
||||||
|
astring * curtext; /* name of the current item */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -217,12 +238,96 @@ static UINT64 execute_tobcd(void *globalref, void *ref, UINT32 params, const UIN
|
|||||||
INLINE FUNCTIONS
|
INLINE FUNCTIONS
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_text_only_cheat - return TRUE if this
|
||||||
|
cheat entry is text-only (no actions)
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_text_only_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_RUN] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_OFF] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_ON] == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_oneshot_cheat - return TRUE if this cheat
|
||||||
|
entry is a one-shot cheat (no "run" or "off"
|
||||||
|
action, but a valid "on" action)
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_oneshot_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_RUN] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_OFF] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_ON] != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_onoff_cheat - return TRUE if this cheat
|
||||||
|
entry is a simple on/off toggle (either the
|
||||||
|
"run" or "off" actions are present)
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_onoff_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter == NULL &&
|
||||||
|
(cheat->script[SCRIPT_STATE_RUN] != NULL ||
|
||||||
|
(cheat->script[SCRIPT_STATE_OFF] != NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_ON] != NULL)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_value_parameter_cheat - return TRUE if this
|
||||||
|
cheat entry has a parameter represented by an
|
||||||
|
integer value
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_value_parameter_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter != NULL && cheat->parameter->itemlist == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_itemlist_parameter_cheat - return TRUE if
|
||||||
|
this cheat entry has a parameter represented
|
||||||
|
by an item list
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_itemlist_parameter_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter != NULL && cheat->parameter->itemlist != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------------------------------------
|
||||||
|
is_oneshot_parameter_cheat - return TRUE if
|
||||||
|
this cheat entry is a one-shot cheat with a
|
||||||
|
parameter (no "run" or "off" actions, but a
|
||||||
|
valid "change" action)
|
||||||
|
-------------------------------------------------*/
|
||||||
|
|
||||||
|
INLINE int is_oneshot_parameter_cheat(const cheat_entry *cheat)
|
||||||
|
{
|
||||||
|
return (cheat->parameter != NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_RUN] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_OFF] == NULL &&
|
||||||
|
cheat->script[SCRIPT_STATE_CHANGE] != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------------------
|
/*-------------------------------------------------
|
||||||
format_int - format an integer according to
|
format_int - format an integer according to
|
||||||
the format
|
the format
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
|
|
||||||
static const char *format_int(astring *string, UINT64 value, int format)
|
INLINE const char *format_int(astring *string, UINT64 value, int format)
|
||||||
{
|
{
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
@ -357,7 +462,7 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
*description = astring_c(cheat->description);
|
*description = astring_c(cheat->description);
|
||||||
|
|
||||||
/* some cheat entries are just text for display */
|
/* some cheat entries are just text for display */
|
||||||
if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL && cheat->script[SCRIPT_STATE_ON] == NULL)
|
if (is_text_only_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (description != NULL)
|
if (description != NULL)
|
||||||
{
|
{
|
||||||
@ -373,7 +478,7 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if we have no parameter and no run or off script, it's a oneshot cheat */
|
/* if we have no parameter and no run or off script, it's a oneshot cheat */
|
||||||
else if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL)
|
else if (is_oneshot_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (state != NULL)
|
if (state != NULL)
|
||||||
*state = "Set";
|
*state = "Set";
|
||||||
@ -382,7 +487,7 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if we have no parameter, it's just on/off */
|
/* if we have no parameter, it's just on/off */
|
||||||
else if (cheat->parameter == NULL)
|
else if (is_onoff_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (state != NULL)
|
if (state != NULL)
|
||||||
*state = (cheat->state == SCRIPT_STATE_RUN) ? "On" : "Off";
|
*state = (cheat->state == SCRIPT_STATE_RUN) ? "On" : "Off";
|
||||||
@ -391,12 +496,11 @@ 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 (is_value_parameter_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->state == SCRIPT_STATE_OFF)
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
{
|
{
|
||||||
if (state != NULL)
|
*state = is_oneshot_parameter_cheat(cheat) ? "Set" : "Off";
|
||||||
*state = "Off";
|
|
||||||
if (flags != NULL)
|
if (flags != NULL)
|
||||||
*flags = MENU_FLAG_RIGHT_ARROW;
|
*flags = MENU_FLAG_RIGHT_ARROW;
|
||||||
}
|
}
|
||||||
@ -417,12 +521,12 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if we have an item list, pick the index */
|
/* if we have an item list, pick the index */
|
||||||
else
|
else if (is_itemlist_parameter_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->state == SCRIPT_STATE_OFF)
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
{
|
{
|
||||||
if (state != NULL)
|
if (state != NULL)
|
||||||
*state = "Off";
|
*state = is_oneshot_parameter_cheat(cheat) ? "Set" : "Off";
|
||||||
if (flags != NULL)
|
if (flags != NULL)
|
||||||
*flags = MENU_FLAG_RIGHT_ARROW;
|
*flags = MENU_FLAG_RIGHT_ARROW;
|
||||||
}
|
}
|
||||||
@ -440,6 +544,7 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
|
|||||||
*flags = MENU_FLAG_LEFT_ARROW;
|
*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;
|
||||||
|
cheat->parameter->itemlist->curtext = item->text; /* Take a copy of the most current parameter for the popmessage (if used) */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,13 +565,24 @@ int cheat_activate(running_machine *machine, void *entry)
|
|||||||
int changed = FALSE;
|
int changed = FALSE;
|
||||||
|
|
||||||
/* if we have no parameter and no run or off script, but we do have an on script, it's a oneshot cheat */
|
/* if we have no parameter and no run or off script, but we do have an on script, it's a oneshot cheat */
|
||||||
if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL && cheat->script[SCRIPT_STATE_ON] != NULL)
|
if (is_oneshot_cheat(cheat))
|
||||||
{
|
{
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
popmessage("Activated %s", astring_c(cheat->description));
|
popmessage("Activated %s", astring_c(cheat->description));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if we have no run or off script, but we do have parameter and change scripts and it's not in the off state, it's a oneshot list or selectable value cheat */
|
||||||
|
else if (is_oneshot_parameter_cheat(cheat) && cheat->state != SCRIPT_STATE_OFF)
|
||||||
|
{
|
||||||
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
|
changed = TRUE;
|
||||||
|
if (cheat->parameter->itemlist != NULL)
|
||||||
|
popmessage("Activated\n %s = %s", astring_c(cheat->description), astring_c(cheat->parameter->itemlist->curtext) );
|
||||||
|
else
|
||||||
|
popmessage("Activated\n %s = %d (0x%X)", astring_c(cheat->description), (UINT32)cheat->parameter->value, (UINT32)cheat->parameter->value );
|
||||||
|
}
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,7 +600,7 @@ int cheat_select_default_state(running_machine *machine, void *entry)
|
|||||||
int changed = FALSE;
|
int changed = FALSE;
|
||||||
|
|
||||||
/* if we have no parameter and no run or off script, it's either text or a oneshot cheat */
|
/* if we have no parameter and no run or off script, it's either text or a oneshot cheat */
|
||||||
if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL)
|
if (is_oneshot_cheat(cheat))
|
||||||
;
|
;
|
||||||
|
|
||||||
/* 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 */
|
||||||
@ -513,11 +629,11 @@ int cheat_select_previous_state(running_machine *machine, void *entry)
|
|||||||
int changed = FALSE;
|
int changed = FALSE;
|
||||||
|
|
||||||
/* if we have no parameter and no run or off script, it's either text or a oneshot cheat */
|
/* if we have no parameter and no run or off script, it's either text or a oneshot cheat */
|
||||||
if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL)
|
if (is_oneshot_cheat(cheat))
|
||||||
;
|
;
|
||||||
|
|
||||||
/* if we have no parameter, it's just on/off */
|
/* if we have no parameter, it's just on/off */
|
||||||
else if (cheat->parameter == NULL)
|
else if (is_onoff_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->state != SCRIPT_STATE_OFF)
|
if (cheat->state != SCRIPT_STATE_OFF)
|
||||||
{
|
{
|
||||||
@ -528,7 +644,7 @@ int cheat_select_previous_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 (is_value_parameter_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->parameter->value > cheat->parameter->minval)
|
if (cheat->parameter->value > cheat->parameter->minval)
|
||||||
{
|
{
|
||||||
@ -536,6 +652,7 @@ int cheat_select_previous_state(running_machine *machine, void *entry)
|
|||||||
cheat->parameter->value = cheat->parameter->minval;
|
cheat->parameter->value = cheat->parameter->minval;
|
||||||
else
|
else
|
||||||
cheat->parameter->value -= cheat->parameter->stepval;
|
cheat->parameter->value -= cheat->parameter->stepval;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
@ -563,6 +680,7 @@ int cheat_select_previous_state(running_machine *machine, void *entry)
|
|||||||
cheat->state = SCRIPT_STATE_RUN;
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
}
|
}
|
||||||
cheat->parameter->value = prev->value;
|
cheat->parameter->value = prev->value;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
@ -589,11 +707,11 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
int changed = FALSE;
|
int changed = FALSE;
|
||||||
|
|
||||||
/* if we have no parameter and no run or off script, it's a oneshot cheat */
|
/* if we have no parameter and no run or off script, it's a oneshot cheat */
|
||||||
if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL)
|
if (is_oneshot_cheat(cheat))
|
||||||
;
|
;
|
||||||
|
|
||||||
/* if we have no parameter, it's just on/off */
|
/* if we have no parameter, it's just on/off */
|
||||||
else if (cheat->parameter == NULL)
|
else if (is_onoff_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->state != SCRIPT_STATE_RUN)
|
if (cheat->state != SCRIPT_STATE_RUN)
|
||||||
{
|
{
|
||||||
@ -604,13 +722,14 @@ 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 (is_value_parameter_cheat(cheat))
|
||||||
{
|
{
|
||||||
if (cheat->state == SCRIPT_STATE_OFF)
|
if (cheat->state == SCRIPT_STATE_OFF)
|
||||||
{
|
{
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
cheat->state = SCRIPT_STATE_RUN;
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
cheat->parameter->value = cheat->parameter->minval;
|
cheat->parameter->value = cheat->parameter->minval;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
@ -620,6 +739,7 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
cheat->parameter->value = cheat->parameter->maxval;
|
cheat->parameter->value = cheat->parameter->maxval;
|
||||||
else
|
else
|
||||||
cheat->parameter->value += cheat->parameter->stepval;
|
cheat->parameter->value += cheat->parameter->stepval;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
@ -635,6 +755,7 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON);
|
||||||
cheat->state = SCRIPT_STATE_RUN;
|
cheat->state = SCRIPT_STATE_RUN;
|
||||||
cheat->parameter->value = cheat->parameter->itemlist->value;
|
cheat->parameter->value = cheat->parameter->itemlist->value;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
@ -646,6 +767,7 @@ int cheat_select_next_state(running_machine *machine, void *entry)
|
|||||||
if (item->next != NULL)
|
if (item->next != NULL)
|
||||||
{
|
{
|
||||||
cheat->parameter->value = item->next->value;
|
cheat->parameter->value = item->next->value;
|
||||||
|
if (!is_oneshot_parameter_cheat(cheat))
|
||||||
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_CHANGE);
|
||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user