If I understand your problem correctly then all you need to do for a joystick to work correctly in mame is modify the mame.ini file. There is an input section, a line for keyboard, mouse and joystick. Make sure you have joystick enabled (value=1). This will allow a joystick to work. As far as Mamewah goes, I know in version 1.62b10 in the Mamewah.cfg file you need to do a similar thing and enable the joystick.
If you are using a keyboard type encoder then all the buttons should work in mamewah right off the bat, otherwise you need to write in the JoyCode_1_Button# in the mamewah.cfg to program Mamewah react accordingly.
Make sense?