It's not real clear what you want, but I think your first question is asking how to add an M-code that will set an output signal, right?
If so, go to Operator->VB Script Editor, and create a new macro file in the appropriate subdirectory of the Mach3\macros directory. For example, if you're using Mach3Mill, and want to define M125, create the file M125.m1s in Mach3\macros\Mach3Mill. This file should contain something like:
ActivateSignal(OutPut4)
or
DeActivateSignal(OutPut4)
to set or clear the pin corresponding to Output4 in your Config->Ports&Pins->Outputs configuration. Putting "M125" in your G-code will execute this macro. I believe you should use a number between 100 and 255, as M codes under 100 are reserved for Mach3.
I don't believe there's any reason you can't use the "OEM Trigger" inputs as additional inputs, so you've got at least 20 outputs and 20 inputs to work with.
Regards,
Ray L.