I have a custom ULA replica from Andy Rea, that can swap black and white with a small ML-routine.
You can also use an ZX8-CCB from Karl/Pokemon where a jumper/switch can swap black and white.
Then you have the option to connect a Lambda Colour Pack or Chroma color extension. With these color expansions you can POKE foreground and background color from Basic.
All in all this is not a software option, as it’s bound to the ULA hardware.
These hardware solutions either replace the ULA, reimplements the ULA, or modifies the internal composite video signal.
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
The main problème in ASM or Basic is to set the black color in the border.
In fact, the border is drawn in the ROM asm display routine, and the hardware locate the right screen offset.
To invers the screen, you had to invers all off TV signals (hardware kits).