hello, i am trying to write an enhanced M0 for mills, so to work just like on lathes ... please, i wish to make it work like this :

M0
if spindle was on M3, than M3
if spindle was on M4, than M4
if spindle was stopped, than stay
etc..

please, how can i detect status for :
... M3 M4 M5
... M08 M51 M120 M09
... M12 M59 ? kindly !