summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2008-08-19 06:08:24 +0000
committer Aaron Giles <aaron@aarongiles.com>2008-08-19 06:08:24 +0000
commitde5cd6e5a8d170cd65be8c19e9820cafdd4e604c (patch)
tree7e7d942934b85850924bea7872ae2da8a768c0e1 /src
parent74777c64205c6c78ae242108b2c11808f29c21ed (diff)
Added cheat functions frombcd() and tobcd() to convert numbers to/from
BCD format. Changed "Activate" to "Set" in the menus.
Diffstat (limited to 'src')
-rw-r--r--src/emu/cheat.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/emu/cheat.c b/src/emu/cheat.c
index 060c3eae6b9..60a18946e3b 100644
--- a/src/emu/cheat.c
+++ b/src/emu/cheat.c
@@ -209,6 +209,8 @@ static astring *quote_astring_expression(astring *string, int isattribute);
static int validate_format(const char *filename, int line, const script_entry *entry);
static UINT64 cheat_variable_get(void *ref);
static void cheat_variable_set(void *ref, UINT64 value);
+static UINT64 execute_frombcd(void *ref, UINT32 params, const UINT64 *param);
+static UINT64 execute_tobcd(void *ref, UINT32 params, const UINT64 *param);
@@ -375,7 +377,7 @@ void *cheat_get_next_menu_entry(running_machine *machine, void *previous, const
else if (cheat->parameter == NULL && cheat->script[SCRIPT_STATE_RUN] == NULL && cheat->script[SCRIPT_STATE_OFF] == NULL)
{
if (state != NULL)
- *state = "Activate";
+ *state = "Set";
if (flags != NULL)
*flags = 0;
}
@@ -918,6 +920,8 @@ static cheat_entry *cheat_entry_load(running_machine *machine, const char *filen
sprintf(tempname, "temp%d", curtemp);
symtable_add_register(cheat->symbols, tempname, &cheat->tempvar[curtemp], cheat_variable_get, cheat_variable_set);
}
+ symtable_add_function(cheat->symbols, "frombcd", NULL, 1, 1, execute_frombcd);
+ symtable_add_function(cheat->symbols, "tobcd", NULL, 1, 1, execute_tobcd);
/* read the first comment node */
commentnode = xml_get_sibling(cheatnode->child, "comment");
@@ -1630,3 +1634,45 @@ static void cheat_variable_set(void *ref, UINT64 value)
{
*(UINT64 *)ref = value;
}
+
+
+/*-------------------------------------------------
+ execute_frombcd - convert a value from BCD
+-------------------------------------------------*/
+
+static UINT64 execute_frombcd(void *ref, UINT32 params, const UINT64 *param)
+{
+ UINT64 value = param[0];
+ UINT64 multiplier = 1;
+ UINT64 result = 0;
+
+ while (value != 0)
+ {
+ result += (value & 0x0f) * multiplier;
+ value >>= 4;
+ multiplier *= 10;
+ }
+ return result;
+}
+
+
+/*-------------------------------------------------
+ execute_tobcd - convert a value to BCD
+-------------------------------------------------*/
+
+static UINT64 execute_tobcd(void *ref, UINT32 params, const UINT64 *param)
+{
+ UINT64 value = param[0];
+ UINT64 result = 0;
+ UINT8 shift = 0;
+
+ while (value != 0)
+ {
+ result += (value % 10) << shift;
+ value /= 10;
+ shift += 4;
+ }
+ return result;
+}
+
+