; extend M0 to:
; turn off spindle, flood, mist if optional stop = 1 and block delete is off
;
; on cycle restart:
; turn on spindle
; turn mist on if it was on before the m1
; turn flood on if it was on before the m1

o<extend_m0> sub
    ;(debug, extend_m0:)

    ; record whether mist/flood were on
    #<mist> = #<_mist>
    #<flood> = #<_flood>
    #<spindle_on> = #<_spindle_on>

    M5 M9 ; stop spindle, mist+flood off

    m0 (refer to builtin m0)

    ; restore mist, flood setting
    o100 if [#<mist>]
        m7
    o100 endif

    o200 if [#<flood>]
        m8
    o200 endif

    o300 if [#<spindle_on>]
        m3 ; spindle on
    o300 endif

    ;(debug, extend_m0 done)

o<extend_m0> endsub
m2
