Sounds like you have +exactly+ my problem.
The issue is how MAME maps joysticks. Mice (or anything that looks like a mouse, like a spinner), etc can be problematic too if you plan on plugging/unplugging them.
Essentially, mame uses DirectInput to enumerate the USB devices, When it does so, Windows always enumerates those devices in order of their VENDOR ID, from what I can tell.
This means that if you have3 joysticks plugged in, they'll enumerate as 1,2,3 in order of their VENDORID (which is basically a random hex number). If you then start mame, and map sticks to inputs, fine.
BUT
If you then plug up another stick, depending on it's VENDORID, it might go AFTER the sticks already in the system, between them, or before them.
If the latter two cases, if you then start mame again, you'll find that some or all of the sticks that were mapped correctly are STILL mapped to the same device numbers, but the actual devices have shifted in the enumeration, so they're mapped wrong.
MGB is right about being able to assign Joystick IDS, and that does work (there's a great program out called JOYIDS.exe that allows you to easily do that). When you set ID's to joysticks, windows will make a pretty good attempt at preserving the joystickID for a given device, even when you unplug and then plug it back in.
Great!
Except mame doesn't appear to use JoystickID's. It +ONLY+ looks at the order of the sticks in the system. (If I'm wrong on this, please someone correct me cause I've searched all over the source and the web for any hint that mame might handle the stick via their ID with no luck).
Bottom line, if you plan on being able to plug and unplug devices from a cab, and you want to use mame, you may or may not be screwed UNLESS you get really lucky and the devices you're going to unplug sort toward the end of the list (IE they've got a higher VENDORID that the devices already in the cab).
I'm actually working on a utility to help mitigate this issue, if you're interested.
The idea is to essentially run +in front+ of mame, look at the devices in the system and change the mame controller mappings to match those devices +right before+ mame runs.
The biggest problem with that approach, unfortunately is that mame completely rewrites the CFG files in the CFG folder, throwing away any +non-mame+ aware settings in those files. No idea why they do it that way, but there it is.
If you're interested, in helping out with the testing or giving me some feedback on it, let me know. I'm planning on releasing it to the community once I'm finished with it, but it's gotta be bulletproof. I don't want to have it fouling up anyone's controller files beyond use!