As for mame config... it's in some type of format other than text.... I haven't had much luck parsing it.
Those dang .cfg files! ;p
They are mostly a binary file. (Units in the file are 8 bit hex pairs, integer(16 bit) = 2 hex pairs, word(32 bit) = 4 hex pairs.)
First are 7 chars ("MAMECFG" to be exact), followed by the version of the config file in hexadecimal ("0x08" currently). After that comes
all the
driver's default input settings, followed by
all the current input settings. Small stuff after that (Coins entered each coin slot, then sound settings).
Each input setting goes (in hex):
input_
type {integer, or 2 pairs},
input_
mask {word, or 4 pairs},
input_
default value {word},
input_
sequence {word, + x# integer(s)}.
type is the input type, such as joystick_left, button1, or spinner. (two hex pairs)
mask contains info like which player #, auto_center, and other stuff. (four hex pairs)
default value is used mostly by analog inputs, and is the "starting" value, or the value centered toward if the mask includes auto_center. (four hex pairs)
sequence starts with the length of the sequence (four hex pairs). The value can be from 0x00 to 0x10 (0-16), depending on how many inputs you have mapped to that input. That number of inputs, represented by two hex pairs, follows. For example, if you had joyButton 0, key "ctrl", and mousebutton 0, mapped to the same input, I think you would have a length of 14 hex pairs: starting with 0x05 {word} followed with: {integers} the 3 inputs separated by 2 "CODE_OR"s (or in pseudocode: input_sequence_length_5 {word}, joybutton0 {integer}, OR {integer}, "ctrl" key {integer}, OR {integer}, mousebutton0 {integer}).
The translation of the numbers to inputs is done in inptport.c, input.c, and [OS]/input.c. The biggest problems are that each input setting can very in length, and each .cfg files can vary which inputs are saved.
We are mostly interested in reading/editing the second set of input settings, as those are the settings used in the games.
Hope this helps anyone.