Yeah, that's pretty much a more formalized description of what I was thinking.
Unfortunately, it already breaks down when moving from the a=0,b=255 case to a=0,b=0x80: In that case, the formula c*2 in fact describes correct hardware behavior, whereas with the "- additive" tricks you would get different results :/
.. but then again that might depend on how you generalize the formular given above. For my testing, I used the general lerp function
which is at least similar to your suggestion for a=0,b=255. I'll need to look at your code snippet again to see to what extend these two are actually equivalent...
Fwiw, I've asked some mame developers for help and one of them told me that it'd probably be useful to have the full tables for different configurations (i.e. other scaling factors than 4). Hence that's what I'll be focusing on for the next few days/weeks (depending on how long the tests take to run... the configurations in the log I provided above already took hours to be tested, but the tests are somewhat unoptimized, so maybe I can cut it down).
Unfortunately, it already breaks down when moving from the a=0,b=255 case to a=0,b=0x80: In that case, the formula c*2 in fact describes correct hardware behavior, whereas with the "- additive" tricks you would get different results :/
.. but then again that might depend on how you generalize the formular given above. For my testing, I used the general lerp function
Code:
int odd_lerp(int a, int b, int c)
{
int diff = b-a;
int add = (c*diff > 255*0xDF) ? 0 : (c*diff > 255*0x9F) ? -1 : (c*diff > 255*0x7F) ? -2 : (c*diff > 255*0x60) ? 2 : (c*diff > 255*0x20) ? 1 : 0;
return 4*a + 4*c*(b-a)/255 - add;
}Fwiw, I've asked some mame developers for help and one of them told me that it'd probably be useful to have the full tables for different configurations (i.e. other scaling factors than 4). Hence that's what I'll be focusing on for the next few days/weeks (depending on how long the tests take to run... the configurations in the log I provided above already took hours to be tested, but the tests are somewhat unoptimized, so maybe I can cut it down).
