Stencil buffer emulation

I'm trying to emulate the stencil buffer of some console hardware with GL. The desired behavior is very simple:
A 1-bit flag controls the stencil value written to the framebuffer (masked or not masked.)
A 1-bit flag controls the stencil test (do not write incoming fragment if framebuffer mask bit is set.)

This behavior is a bit different than GL's stenciling:
Disabling the stencil test does not disable writing the stencil bit (it is always written, unless the stencil test fails.)
GL shares one reference for both the stencil value to write and the value to test against.

Those two things are making it hard for me to map this behavior to GL:

Here, STENCIL_TEST is always enabled so the bit is always written along with the color value, unless the test fails, per StencilOp.

The problem is that the bit to write is shared with the reference value to test-- if bCheckMask is false, I correctly write out the mask bit, and always pass the test.
But if bCheckMask is true, I want to write out the mask bit, but only pass if the framebuffer bit is 0. There's no GL enumeration to do that!

A mask bit of 1 signifies 'do not write', but otherwise yes, breaking it apart like that allows the functionality I wanted. Thanks!

Unfortuntely, it turns out that for textured primitives, there is an additional interaction with the high bit of the (paletted) texel color-- if it is set (opaque) the mask bit is also set. So, the stencil buffer isn't going to work out here after all... I'll have to come up with something else.