diff options
| author | 2009-09-10 07:17:35 +0000 | |
|---|---|---|
| committer | 2009-09-10 07:17:35 +0000 | |
| commit | 8f9ec7de59297c747451f2cf67a0a1ae6b6fc885 (patch) | |
| tree | 91c7279b6bbd47d14569cf971abe45354fc0c82b | |
| parent | 224c8d3f97a124872fdf2c15630004a68d97c233 (diff) | |
Hooked up F6 again as a global cheat enable/disable. [Pugsy]
| -rw-r--r-- | src/emu/cheat.c | 57 | ||||
| -rw-r--r-- | src/emu/cheat.h | 6 | ||||
| -rw-r--r-- | src/emu/ui.c | 4 | ||||
| -rw-r--r-- | src/emu/uimenu.c | 4 |
4 files changed, 68 insertions, 3 deletions
diff --git a/src/emu/cheat.c b/src/emu/cheat.c index 1f5686c46f5..bc5a05c89da 100644 --- a/src/emu/cheat.c +++ b/src/emu/cheat.c @@ -203,8 +203,9 @@ struct _cheat_private UINT64 framecount; /* frame count */ astring * output[UI_TARGET_FONT_ROWS*2]; /* array of output strings */ UINT8 justify[UI_TARGET_FONT_ROWS*2]; /* justification for each string */ - UINT8 numlines; /* nnumber of lines available for output */ + UINT8 numlines; /* number of lines available for output */ INT8 lastline; /* last line used for output */ + UINT8 disabled; /* true if the cheat engine is disabled */ }; @@ -446,6 +447,52 @@ static void cheat_exit(running_machine *machine) } +/*------------------------------------------------- + cheat_get_global_enable - return the global + enabled state of the cheat engine +-------------------------------------------------*/ + +int cheat_get_global_enable(running_machine *machine) +{ + cheat_private *cheatinfo = machine->cheat_data; + return !cheatinfo->disabled; +} + + +/*------------------------------------------------- + cheat_set_global_enable - globally enable or + disable the cheat engine +-------------------------------------------------*/ + +void cheat_set_global_enable(running_machine *machine, int enable) +{ + cheat_private *cheatinfo = machine->cheat_data; + cheat_entry *cheat; + + /* if we're enabled currently and we don't want to be, turn things off */ + if (!cheatinfo->disabled && !enable) + { + /* iterate over running cheats and execute any OFF Scripts */ + for (cheat = cheatinfo->cheatlist; cheat != NULL; cheat = cheat->next) + if (cheat->state == SCRIPT_STATE_RUN) + cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_OFF); + popmessage("Cheats Disabled"); + cheatinfo->disabled = TRUE; + } + + /* if we're disabled currently and we want to be enabled, turn things on */ + else if (cheatinfo->disabled && enable) + { + /* iterate over running cheats and execute any ON Scripts */ + cheatinfo->disabled = FALSE; + for (cheat = cheatinfo->cheatlist; cheat != NULL; cheat = cheat->next) + if (cheat->state == SCRIPT_STATE_RUN) + cheat_execute_script(cheatinfo, cheat, SCRIPT_STATE_ON); + popmessage("Cheats Enabled"); + } +} + + /*************************************************************************** CHEAT UI @@ -601,6 +648,10 @@ int cheat_activate(running_machine *machine, void *entry) cheat_private *cheatinfo = machine->cheat_data; cheat_entry *cheat = (cheat_entry *)entry; int changed = FALSE; + + /* if cheats have been toggled off no point in even trying to do anything */ + if (cheatinfo->disabled) + return changed; /* if we have no parameter and no run or off script, but we do have an on script, it's a oneshot cheat */ if (is_oneshot_cheat(cheat)) @@ -872,8 +923,8 @@ static void cheat_execute_script(cheat_private *cheatinfo, cheat_entry *cheat, s { script_entry *entry; - /* if no script, bail */ - if (cheat->script[state] == NULL) + /* if cheat engine has been temporarily disabled or no script, bail */ + if (cheatinfo->disabled || cheat->script[state] == NULL) return; /* iterate over entries */ diff --git a/src/emu/cheat.h b/src/emu/cheat.h index 2966aadfbd7..2fcfbb2d721 100644 --- a/src/emu/cheat.h +++ b/src/emu/cheat.h @@ -31,6 +31,12 @@ void cheat_init(running_machine *machine); /* re-initialize the cheat system, reloading any cheat files */ void cheat_reload(running_machine *machine); +/* return the global enabled state of the cheat engine */ +int cheat_get_global_enable(running_machine *machine); + +/* globally enable or disable the cheat engine */ +void cheat_set_global_enable(running_machine *machine, int enable); + /* ----- cheat UI helpers ----- */ diff --git a/src/emu/ui.c b/src/emu/ui.c index 4682c26ac07..77620602d7d 100644 --- a/src/emu/ui.c +++ b/src/emu/ui.c @@ -1236,6 +1236,10 @@ static UINT32 handler_ingame(running_machine *machine, UINT32 state) mame_pause(machine, !mame_is_paused(machine)); } + /* handle a toggle cheats request */ + if (ui_input_pressed(machine, IPT_UI_TOGGLE_CHEAT)) + cheat_set_global_enable(machine, !cheat_get_global_enable(machine)); + /* toggle movie recording */ if (ui_input_pressed(machine, IPT_UI_RECORD_MOVIE)) { diff --git a/src/emu/uimenu.c b/src/emu/uimenu.c index 80a6e1ec1b3..3ed2962142b 100644 --- a/src/emu/uimenu.c +++ b/src/emu/uimenu.c @@ -1228,6 +1228,10 @@ static void ui_menu_handle_keys(ui_menu *menu, UINT32 flags) if (!ignorepause && exclusive_input_pressed(menu, IPT_UI_PAUSE, 0)) mame_pause(menu->machine, !mame_is_paused(menu->machine)); + /* handle a toggle cheats request */ + if (exclusive_input_pressed(menu, IPT_UI_TOGGLE_CHEAT, 0)) + cheat_set_global_enable(menu->machine, !cheat_get_global_enable(menu->machine)); + /* see if any other UI keys are pressed */ if (menu->event.iptkey == IPT_INVALID) for (code = __ipt_ui_start; code <= __ipt_ui_end; code++) |
