While the power is coming in to the regulator, the zener feeds a voltage to the base of the transistor, which switches on, keeping the DCgone pin low.
The normal loop keeps running while the DCgone pin is low, but when the incoming voltage drops below about 8 volts, the transistor switches off, but the 470mF capacitor is still charged ( the diode stops the power supply discharging the 470mF cap )and supplies 5 volts to the chip for about half a second.
On the next loop, the DCgone pin is high, and the variables are saved to the eeprom in the chip.
The unsaved flag only allows it to save the data once, as you dont want it to keep saving every loop as the 5 volt fades away.
When the power comes on again, the saved variables are read from the eeprom during setup.