2006.09.16
I've included Shimapong's numerous fixes "as is" ... The only important thing I've change is that I didn't like the "code_pressed_memory(KEYCODE_R)" : you should use "input_ui_pressed(IPT_UI_RELOAD_CHEAT)" instead ...
This means that I had to modify src/inptport.h and src/inptport.c to add the new key to the UI ... BTW, note that I had to change the key to 'L' because 'R' was already used to rotate the screen ...
While I was at it, I've created a "static void ReloadCheatDatabase(void);" function for easier changes in the future (if any) ...
Now, before I submit the source files to you, I'd like to modify the way numeric data is edited and I REALLY need feedback ...
At the moment, I have found 4 main functions :
. static int ReadHexInput(void);
. static UINT32 DoEditHexField(UINT32 data);
. static UINT32 DoEditHexFieldSigned(UINT32 data, UINT32 mask);
. static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max);
What we should have (sort of) :
1) static int ReadDigit(int pBase, int BCDonly);
This would allow to correctly read a digit (ie with the keyboard AND the keypad) depending on the "pBase" parameter (2 for binary, 8 for octal, 10 for decimal and 16 for hexa) and the BCDonly "flag" (!= 0 when set) ... Binary and octal support might not be useful, but it's not that difficult to add them if we ever need such stuff one day or another ...
Code: Select all
static int ReadDigit(int pBase, int BCDonly)
{
int i, digit;
if ((pBase == 16) && (BCDonly)) /* adjust max value */
pBase = 10;
digit = -1; /* no good key pressed */
for(i = 0; i < 10; i++)
{
if(code_pressed_memory(KEYCODE_0 + i))
{
digit = i;
}
}
for(i = 0; i < 10; i++)
{
if(code_pressed_memory(KEYCODE_0_PAD + i))
{
digit = i;
}
}
for(i = 0; i < 6; i++)
{
if(code_pressed_memory(KEYCODE_A + i))
{
digit = i + 10;
}
}
if (digit > pBase)
digit = -1;
return digit;
}
2) static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max);
This function is good to me, but it needs to call ReadDigit and handle the specific keys (backspace and "-") ...
Code: Select all
static INT32 DoEditDecField(INT32 data, INT32 min, INT32 max)
{
int digit = ReadDigit(kBaseDecimal, 0)
char code = osd_readkey_unicode(0) & 0xFF;
if (digit != -1)
{
data *= kBaseDecimal;
data += digit;
}
else if (code == '-')
{
data = -data;
}
else if (code == 0x08)
{
data /= kBaseDecimal;
}
if (data < min)
data = min;
if (data > max)
data = max;
return data;
}
Note that there's a bug in Shimapong's fix : when you press BACKSPACE, you shall compute "data /= 10" instead of "data >> 4" (we're in DECIMAL !) ... Fast copy/paste without checking I guess ...
3) static static UINT32 DoEditHexField(UINT32 data, int BCDonly)
This function should now be very similar to the previous one if you except the fact that you can't have a negative value ...
Code: Select all
static static UINT32 DoEditHexField(UINT32 data, int BCDonly)
{
int digit = ReadDigit(kBaseHexadecimal, BCDonly)
char code = osd_readkey_unicode(0) & 0xFF;
if (digit != -1)
{
data *= kBaseHexadecimal;
data += digit;
}
else if (code == 0x08)
{
data /= kBaseHexadecimal;
}
return data;
}
Now I wonder if we REALLY need to have a way to edit negative hexadecimal values : from what I see in the source file, the old routine was only called to change the data in case of menu on kType_WatchAddValue and it was only for a byte change (thing that can easily be done with the arrows keys) ...
4) static float DoEditFloatField(float data, float min, float max, int maxDecimals)
Heavily based on function 2, it will be used for the watches positions (unless we decide to have UINT32 values that will be computed during the display) ... The maxDecimals parameter is used to prevent long entries ... No proposition at the moment on how it will be coded, I must think a bit more about it first ...
That's all for now (I think it's enough for a first proposition) ... Comments are welcome ...

Steph from The Ultimate Patchers
