The problem is 8way sticks do diagonals, and no software or hardware can tell if you're moving from up to left, or if you accidently are pushing up-left when you still want up.
There's only four real solutions: a) get a 4-way, b) get a restrictor plate, c) get an 8-way with small diagonals, d) get an analog stick and add analog-to-4way logic to mame / hardware. A bad solution: become very good at staying straight up or down or left or right, and never hit diagonals.
Mame's source:
/* If joystick is pointing at a diagonal, acknowledge that the player moved
* the joystick by favoring a direction change. This minimizes frustration
* when using a keyboard for input, and maximizes responsiveness.
*
* For example, if you are holding "left" then switch to "up" (where both left
* and up are briefly pressed at the same time), we'll transition immediately
* to "up."
*
* Under the old "sticky" key implentation, "up" wouldn't be triggered until
* left was released.
... code logic ...
/* If we are still pointing at a diagonal, ....
* the player moved the joystick from the idle position directly
* to a diagonal, or from one diagonal directly to an extreme diagonal.
*
* The chances of this happening with a keyboard are slim, but we still need to
* constrain this case.
*
* For now, just resolve randomly.
*/
This logic is fine if you have small diagonals, but if you have pretty big diags, so big you sometimes accidentally hit the diag when you don't want to, this logic can case problems. IE, you're holding up, and slide to mostly-up but hitting-a-"up-left"-diag, mame assumes you're switching from up to left. All of a sudden, you're going left even though you're holding mostly up.
BTW, this logic is exactly what most people discribe when making a hardware logic board that switches 8-way to "be like a 4-way".
Mame used to do it the other way (ie: the direction which was hit first stayed as the "4-way direction" until that direction was stopped being pressed.) But that ran into "to slow" complaints, and was dropped.
BTW, this logic is exactly what others discribe in their hardware logic board that switches 8-way to "be like a 4-way".
So many people complain about both software/hardware ways of simulating 4-ways, some driver writers have said, "screw it, I'll call it an 8way in the driver, and let the user have to use real 4-way hardware" instead of having to listen to all the complaints.
I seriously doubt there is a way to simulate 4way with 8way sticks that works with all 8way sticks and keyboards so well it satisfies most people. They all have been tried.
BTW, that analog solution + hardware logic board can have a switch to a 8 way or 4 way. You could even have it switch between analog, 8way, and 4way logic. Only way if you really want to be able from 8way to 4way on the same stick, besides a restrictor plate of course.
Analog logic:
Send analog signal straight through.
4way logic:
(this is set so if they're push far enough, which ever direction is pushed more is set as the direction. See shown, the 45 degree directions favor up and down over left and right, but it has to be exactly a diagonal. Assuming up and left being negative values on the analog stick. This can also be done in software, too, be currently isn't in mame.)
If |X| > min angle and |X| > |Y|
{
if X is negative {direction = "left"}
else {direction = "right"}
}
else if |Y| > min angle and |Y| >= |X|
{
if Y is negative {direction = "up"
else {direction = "down"}
}
else
direction = "center"8way logic
(many ways to do this. The following is pretty much how swithes on an 8way do it, assuming up and left being negative values on the analog stick)
If X < min up value, up = true
if X > min down value, down = true
if Y < min left value, left = true
if Y > min right value, right = true