flip-flop

xod/core/flip-flop

Permanently holds either 0 or 1
flip-flop
@/flip-flop
Permanently holds either 0 or 1
SETpulse
Sets stored value to 1
TGLpulse
Toggles (inverts) stored value
RSTpulse
Sets stored value to 0
flip-flop
SET
TGL
RST
MEM
MEMboolean
The stored value

C++ implementation

node {
    void evaluate(Context ctx) {
        bool oldState = getValue<output_MEM>(ctx);
        bool newState = oldState;

        if (isInputDirty<input_RST>(ctx)) {
            newState = false;
        } else if (isInputDirty<input_SET>(ctx)) {
            newState = true;
        } else if (isInputDirty<input_TGL>(ctx)) {
            newState = !oldState;
        }

        if (newState == oldState)
            return;

        emitValue<output_MEM>(ctx, newState);
    }
}

Tabular tests

SETTGLRSTMEM
no-pulseno-pulseno-pulsefalse
pulseno-pulseno-pulsetrue
no-pulsepulseno-pulsefalse
no-pulsepulseno-pulsetrue
no-pulseno-pulseno-pulsetrue
no-pulseno-pulsepulsefalse
no-pulseno-pulsepulsefalse
pulsepulsepulsefalse
pulsepulsepulsefalse
pulsepulseno-pulsetrue
pulsepulseno-pulsetrue
no-pulsepulseno-pulsefalse