--- hatari/src/debug/evaluate.c 2019/04/09 08:49:26 1.1.1.2 +++ hatari/src/debug/evaluate.c 2019/04/09 08:58:04 1.1.1.7 @@ -1,10 +1,10 @@ /* - Hatari - calculate.c + Hatari - evaluate.c - Copyright (C) 1994, 2009-2010 by Eero Tamminen + Copyright (C) 1994, 2009-2014 by Eero Tamminen - This file is distributed under the GNU Public License, version 2 or at - your option any later version. Read the file gpl.txt for details. + This file is distributed under the GNU General Public License, version 2 + or at your option any later version. Read the file gpl.txt for details. calculate.c - parse numbers, number ranges and expressions. Supports most unary and binary operations. Parenthesis are used for indirect @@ -21,7 +21,7 @@ const char Eval_fileid[] = "Hatari calcu #include #include #include -#include "breakcond.h" +#include #include "configuration.h" #include "dsp.h" #include "debugcpu.h" @@ -30,6 +30,8 @@ const char Eval_fileid[] = "Hatari calcu #include "m68000.h" #include "stMemory.h" #include "symbols.h" +#include "vars.h" + /* define which character indicates which type of number on expression */ #define PREFIX_BIN '%' /* binary decimal */ @@ -58,7 +60,7 @@ const char Eval_fileid[] = "Hatari calcu static struct { const char *error; /* global error code */ bool valid; /* value validation */ -} id = {0, 0}; +} id = { NULL, 0 }; /* parenthesis and function stacks */ static struct { @@ -126,7 +128,7 @@ static long long close_bracket(long long static int getNumber(const char *str, Uint32 *number, int *nbase) { char *end; - const char const *start = str; + const char *start = str; int base = ConfigureParams.Debugger.nNumberBase; unsigned long int value; @@ -158,7 +160,7 @@ static int getNumber(const char *str, Ui } str += 2; } - else if (!isxdigit(str[0])) { + else if (!isxdigit((unsigned char)str[0])) { /* doesn't start with (hex) number -> is it prefix? */ switch (*str++) { @@ -206,8 +208,8 @@ static int getValue(const char *str, Uin Uint32 mask, *addr; int len; - for (end = str; *end == '_' || isalnum(*end); end++); - + for (end = str; *end == '_' || isalnum((unsigned char)*end); end++); + len = end-str; if (len >= (int)sizeof(name)) { fprintf(stderr, "ERROR: symbol name at '%s' too long (%d chars)\n", str, len); @@ -219,18 +221,24 @@ static int getValue(const char *str, Uin *base = 0; /* no base (e.g. variable) */ /* internal Hatari variable? */ - if (BreakCond_GetHatariVariable(name, number)) { + if (Vars_GetVariableValue(name, number)) { return len; } if (bForDsp) { + int regsize = DSP_GetRegisterAddress(name, &addr, &mask); /* DSP register or symbol? */ - if (DSP_GetRegisterAddress(name, &addr, &mask)) { - *number = (*addr & mask); + switch (regsize) { + case 16: + *number = (*((Uint16*)addr) & mask); return len; - } - if (Symbols_GetDspAddress(SYMTYPE_ALL, name, number)) { + case 32: + *number = (*addr & mask); return len; + default: + if (Symbols_GetDspAddress(SYMTYPE_ALL, name, number)) { + return len; + } } } else { /* a special case CPU register? */ @@ -308,7 +316,10 @@ bool Eval_Number(const char *str, Uint32 * addition to numbers. */ offset = getNumber(str, number, &base); - return isNumberOK(str, offset, base); + if (!offset) + return false; + else + return isNumberOK(str, offset, base); } @@ -337,7 +348,7 @@ int Eval_Range(char *str1, Uint32 *lower } offset = getValue(str1, lower, &base, fordsp); - if (!isNumberOK(str1, offset, base)) { + if (offset == 0 || !isNumberOK(str1, offset, base)) { /* first number not OK */ fprintf(stderr,"Invalid address value '%s'!\n", str1); ret = -1; @@ -347,7 +358,7 @@ int Eval_Range(char *str1, Uint32 *lower } if (fDash) { offset = getValue(str2, upper, &base, fordsp); - if (!isNumberOK(str2, offset, base)) { + if (offset == 0 || !isNumberOK(str2, offset, base)) { /* second number not OK */ fprintf(stderr, "Invalid address value '%s'!\n", str2); ret = -1; @@ -652,6 +663,7 @@ static long long apply_op (char opcode, break; case '>': value1 >>= value2; + break; case '<': value1 <<= value2; break; @@ -683,7 +695,7 @@ static long long apply_op (char opcode, /* ==================================================================== */ /** - * open prenthesis, push values & operators to stack + * open parenthesis, push values & operators to stack */ static void open_bracket (void) { @@ -700,7 +712,7 @@ static void open_bracket (void) /* -------------------------------------------------------------------- */ /** - * close prenthesis, and evaluate / pop stacks + * close parenthesis, and evaluate / pop stacks */ /* last parsed value, last param. flag, trigonometric mode */ static long long close_bracket (long long value) @@ -708,7 +720,7 @@ static long long close_bracket (long lon /* returns the value of the parenthesised expression */ if (id.valid) { /* preceded by an operator */ - if (par.idx > 0) { /* prenthesis has a pair */ + if (par.idx > 0) { /* parenthesis has a pair */ Uint32 addr; /* calculate the value of parenthesised exp. */ @@ -716,7 +728,8 @@ static long long close_bracket (long lon /* fetch the indirect ST RAM value */ addr = val.buf[val.idx]; value = STMemory_ReadLong(addr); - fprintf(stderr, " value in RAM at ($%x).l = $%llx\n", addr, value); + fprintf(stderr, " value in RAM at ($%x).l = $%"PRIx64"\n", + addr, (uint64_t)value); /* restore state before parenthesis */ op.idx = par.opx[par.idx] - 1; val.idx = par.vax[par.idx] - 1;